Simon Peyton Jones pushed to branch wip/ani/kill-SrcCodeOrigin at Glasgow Haskell Compiler / GHC
Commits:
-
5cca9b8d
by Simon Peyton Jones at 2026-02-27T00:44:47+00:00
24 changed files:
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Gen/Match.hs-boot
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Solver/Solve.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Class.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/Types/BasicTypes.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Types/Origin.hs-boot
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Validity.hs
Changes:
| ... | ... | @@ -21,6 +21,7 @@ import GHC.Driver.Session |
| 21 | 21 | import GHC.Tc.Errors.Types
|
| 22 | 22 | import GHC.Tc.Instance.Family
|
| 23 | 23 | import GHC.Tc.Types.Origin
|
| 24 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt(..) )
|
|
| 24 | 25 | import GHC.Tc.Deriv.Infer
|
| 25 | 26 | import GHC.Tc.Deriv.Utils
|
| 26 | 27 | import GHC.Tc.Deriv.Generate
|
| ... | ... | @@ -695,7 +696,7 @@ deriveStandalone (L loc (DerivDecl (warn, _) deriv_ty mb_lderiv_strat overlap_mo |
| 695 | 696 | = setSrcSpanA loc $
|
| 696 | 697 | addErrCtxt (StandaloneDerivCtxt deriv_ty) $
|
| 697 | 698 | do { traceTc "Standalone deriving decl for" (ppr deriv_ty)
|
| 698 | - ; let ctxt = GHC.Tc.Types.Origin.InstDeclCtxt True
|
|
| 699 | + ; let ctxt = GHC.Tc.Types.ErrCtxt.InstDeclCtxt True
|
|
| 699 | 700 | ; traceTc "Deriving strategy (standalone deriving)" $
|
| 700 | 701 | vcat [ppr mb_lderiv_strat, ppr deriv_ty]
|
| 701 | 702 | ; (mb_lderiv_strat, via_tvs) <- tcDerivStrategy mb_lderiv_strat
|
| ... | ... | @@ -37,6 +37,7 @@ import GHC.Tc.Deriv.Generics |
| 37 | 37 | import GHC.Tc.Errors.Types
|
| 38 | 38 | import GHC.Tc.Types.Constraint (WantedConstraints, mkNonCanonical)
|
| 39 | 39 | import GHC.Tc.Types.Origin
|
| 40 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt( InstDeclCtxt, DerivClauseCtxt ) )
|
|
| 40 | 41 | import GHC.Tc.Utils.Monad
|
| 41 | 42 | import GHC.Tc.Utils.TcType
|
| 42 | 43 | import GHC.Tc.Utils.Unify (tcSubTypeSigma)
|
| ... | ... | @@ -33,6 +33,7 @@ import GHC.Tc.Zonk.Type |
| 33 | 33 | import GHC.Tc.Utils.TcType
|
| 34 | 34 | import GHC.Tc.Zonk.TcType
|
| 35 | 35 | import GHC.Tc.Types.Origin
|
| 36 | +import GHC.Tc.Types.ErrCtxt( redundantConstraintsSpan )
|
|
| 36 | 37 | import GHC.Tc.Types.Evidence
|
| 37 | 38 | import GHC.Tc.Instance.Family
|
| 38 | 39 | import GHC.Tc.Utils.Instantiate
|
| ... | ... | @@ -7703,11 +7703,17 @@ pprErrCtxtMsg = \case |
| 7703 | 7703 | make_lines_msg [last] = ppr last <> dot
|
| 7704 | 7704 | make_lines_msg [l1,l2] = l1 $$ text "and" <+> l2 <> dot
|
| 7705 | 7705 | make_lines_msg (l:ls) = l <> comma $$ make_lines_msg ls
|
| 7706 | + |
|
| 7706 | 7707 | PatSigErrCtxt sig_ty res_ty ->
|
| 7707 | 7708 | vcat [ hang (text "When checking that the pattern signature:")
|
| 7708 | 7709 | 4 (ppr sig_ty)
|
| 7709 | - , nest 2 (hang (text "fits the type of its context:")
|
|
| 7710 | - 2 (ppr res_ty)) ]
|
|
| 7710 | + , nest 2 (hang (text "fits the type of its context:") 2 pp_res_ty) ]
|
|
| 7711 | + where
|
|
| 7712 | + -- Zonking will have turned Infer into Check
|
|
| 7713 | + pp_res_ty = case res_ty of
|
|
| 7714 | + Check ty -> ppr ty
|
|
| 7715 | + Infer ir -> text "OOPS" <+> ppr ir
|
|
| 7716 | + |
|
| 7711 | 7717 | PatCtxt pat ->
|
| 7712 | 7718 | hang (text "In the pattern:") 2 (ppr pat)
|
| 7713 | 7719 | PatSynDeclCtxt name ->
|
| ... | ... | @@ -184,7 +184,7 @@ import GHC.Tc.Types.Constraint |
| 184 | 184 | import GHC.Tc.Types.Evidence (EvBindsVar)
|
| 185 | 185 | import GHC.Tc.Types.ErrCtxt
|
| 186 | 186 | import GHC.Tc.Types.Origin ( CtOrigin (ProvCtxtOrigin), SkolemInfoAnon (SigSkol)
|
| 187 | - , UserTypeCtxt (PatSynCtxt), TyVarBndrs, TypedThing
|
|
| 187 | + , TyVarBndrs, TypedThing
|
|
| 188 | 188 | , FixedRuntimeRepOrigin(..), InstanceWhat )
|
| 189 | 189 | import GHC.Tc.Types.CtLoc( CtLoc, ctLocOrigin, SubGoalDepth )
|
| 190 | 190 | import GHC.Tc.Types.Rank (Rank)
|
| ... | ... | @@ -35,6 +35,7 @@ import GHC.Tc.Gen.Sig |
| 35 | 35 | import GHC.Tc.Utils.Concrete ( hasFixedRuntimeRep_syntactic )
|
| 36 | 36 | import GHC.Tc.Utils.Monad
|
| 37 | 37 | import GHC.Tc.Types.Origin
|
| 38 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 38 | 39 | import GHC.Tc.Utils.Env
|
| 39 | 40 | import GHC.Tc.Utils.Unify
|
| 40 | 41 | import GHC.Tc.Solver
|
| ... | ... | @@ -41,6 +41,7 @@ import GHC.Tc.Errors.Types |
| 41 | 41 | import GHC.Tc.Solver ( InferMode(..), simplifyInfer )
|
| 42 | 42 | import GHC.Tc.Utils.Env
|
| 43 | 43 | import GHC.Tc.Utils.TcMType
|
| 44 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 44 | 45 | import GHC.Tc.Types.Origin
|
| 45 | 46 | import GHC.Tc.Types.Constraint( WantedConstraints )
|
| 46 | 47 | import GHC.Tc.Utils.TcType as TcType
|
| ... | ... | @@ -52,6 +52,7 @@ import GHC.Tc.Gen.Bind |
| 52 | 52 | import GHC.Tc.Utils.Concrete ( hasFixedRuntimeRep_syntactic )
|
| 53 | 53 | import GHC.Tc.Utils.Unify
|
| 54 | 54 | import GHC.Tc.Types.Origin
|
| 55 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt( GenSigCtxt ), pprUserTypeCtxt )
|
|
| 55 | 56 | import GHC.Tc.Types.Evidence
|
| 56 | 57 | import GHC.Rename.Env ( irrefutableConLikeTc )
|
| 57 | 58 |
| ... | ... | @@ -2,7 +2,7 @@ module GHC.Tc.Gen.Match where |
| 2 | 2 | import GHC.Hs ( GRHSs, MatchGroup, LHsExpr, Mult )
|
| 3 | 3 | import GHC.Tc.Utils.TcType( ExpSigmaType, ExpRhoType, ExpPatType )
|
| 4 | 4 | import GHC.Tc.Types ( TcM )
|
| 5 | -import GHC.Tc.Types.Origin ( UserTypeCtxt )
|
|
| 5 | +import GHC.Tc.Types.ErrCtxt ( UserTypeCtxt )
|
|
| 6 | 6 | import GHC.Tc.Types.Evidence ( HsWrapper )
|
| 7 | 7 | import GHC.Types.Name ( Name )
|
| 8 | 8 | import GHC.Hs.Extension ( GhcRn, GhcTc )
|
| ... | ... | @@ -1021,8 +1021,7 @@ tcPatSig in_pat_bind sig res_ty |
| 1021 | 1021 | ; case NE.nonEmpty sig_tvs of
|
| 1022 | 1022 | Nothing -> do {
|
| 1023 | 1023 | -- Just do the subsumption check and return
|
| 1024 | - msg <- mk_msg res_ty sig_ty
|
|
| 1025 | - ; wrap <- addErrCtxtM msg $
|
|
| 1024 | + ; wrap <- addErrCtxtM (PatSigErrCtxt sig_ty res_ty) $
|
|
| 1026 | 1025 | tcSubTypePat PatSigOrigin PatSigCtxt res_ty sig_ty
|
| 1027 | 1026 | ; return (sig_ty, [], sig_wcs, wrap)
|
| 1028 | 1027 | }
|
| ... | ... | @@ -1036,17 +1035,12 @@ tcPatSig in_pat_bind sig res_ty |
| 1036 | 1035 | (addErr (TcRnCannotBindScopedTyVarInPatSig sig_tvs_ne))
|
| 1037 | 1036 | |
| 1038 | 1037 | -- Now do a subsumption check of the pattern signature against res_ty
|
| 1039 | - msg <- mk_msg res_ty sig_ty
|
|
| 1040 | - wrap <- addErrCtxtM msg $
|
|
| 1038 | + wrap <- addErrCtxtM (PatSigErrCtxt sig_ty res_ty) $
|
|
| 1041 | 1039 | tcSubTypePat PatSigOrigin PatSigCtxt res_ty sig_ty
|
| 1042 | 1040 | |
| 1043 | 1041 | -- Phew!
|
| 1044 | 1042 | return (sig_ty, sig_tvs, sig_wcs, wrap)
|
| 1045 | 1043 | }
|
| 1046 | - where
|
|
| 1047 | - mk_msg res_ty sig_ty
|
|
| 1048 | - = do { res_ty <- readExpType res_ty -- should be filled in by now
|
|
| 1049 | - ; return $ PatSigErrCtxt sig_ty res_ty }
|
|
| 1050 | 1044 | |
| 1051 | 1045 | {- *********************************************************************
|
| 1052 | 1046 | * *
|
| ... | ... | @@ -50,6 +50,7 @@ import GHC.Tc.Utils.Instantiate( topInstantiate, tcInstTypeBndrs ) |
| 50 | 50 | import GHC.Tc.Utils.Env
|
| 51 | 51 | |
| 52 | 52 | import GHC.Tc.Types.Origin
|
| 53 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 53 | 54 | import GHC.Tc.Types.Evidence
|
| 54 | 55 | import GHC.Tc.Types.Constraint
|
| 55 | 56 |
| ... | ... | @@ -65,6 +65,7 @@ import GHC.Tc.Utils.Monad |
| 65 | 65 | import GHC.Tc.Gen.Export
|
| 66 | 66 | import GHC.Tc.Types.Evidence
|
| 67 | 67 | import GHC.Tc.Types.Constraint
|
| 68 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 68 | 69 | import GHC.Tc.Types.Origin
|
| 69 | 70 | import GHC.Tc.Instance.Family
|
| 70 | 71 | import GHC.Tc.Gen.Annotation
|
| ... | ... | @@ -23,6 +23,7 @@ import GHC.Tc.Types.Evidence |
| 23 | 23 | import GHC.Tc.Types.CtLoc( ctLocEnv, ctLocOrigin, setCtLocOrigin )
|
| 24 | 24 | import GHC.Tc.Types
|
| 25 | 25 | import GHC.Tc.Types.Origin
|
| 26 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt(..), reportRedundantConstraints )
|
|
| 26 | 27 | import GHC.Tc.Types.Constraint
|
| 27 | 28 | import GHC.Tc.Types.CtLoc( mkGivenLoc )
|
| 28 | 29 | import GHC.Tc.Solver.InertSet
|
| ... | ... | @@ -58,6 +58,7 @@ import GHC.Tc.Instance.Family |
| 58 | 58 | import GHC.Tc.Types.ErrCtxt ( TyConInstFlavour(..) )
|
| 59 | 59 | import GHC.Tc.Types.LclEnv
|
| 60 | 60 | import GHC.Tc.Types.Origin
|
| 61 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 61 | 62 | |
| 62 | 63 | import GHC.Builtin.Types ( oneDataConTy, unitTy, makeRecoveryTyCon, manyDataConTy )
|
| 63 | 64 |
| ... | ... | @@ -38,6 +38,7 @@ import GHC.Tc.Utils.Unify |
| 38 | 38 | import GHC.Tc.Utils.Instantiate( newFamInst, tcSuperSkolTyVars )
|
| 39 | 39 | import GHC.Tc.Gen.HsType
|
| 40 | 40 | import GHC.Tc.Utils.TcMType
|
| 41 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 41 | 42 | import GHC.Tc.Types.Origin
|
| 42 | 43 | import GHC.Tc.Utils.TcType
|
| 43 | 44 | import GHC.Tc.Utils.Monad
|
| ... | ... | @@ -38,6 +38,7 @@ import GHC.Tc.Utils.TcMType |
| 38 | 38 | import GHC.Tc.Utils.TcType
|
| 39 | 39 | import GHC.Tc.Types.Constraint
|
| 40 | 40 | import GHC.Tc.Types.Origin
|
| 41 | +import GHC.Tc.Types.ErrCtxt( ReportRedundantConstraints(..) )
|
|
| 41 | 42 | import GHC.Tc.TyCl.Build
|
| 42 | 43 | import GHC.Tc.Utils.Instantiate
|
| 43 | 44 | import GHC.Tc.Instance.Class( AssocInstInfo(..), isNotAssociated )
|
| ... | ... | @@ -32,6 +32,7 @@ import GHC.Tc.Utils.Unify |
| 32 | 32 | import GHC.Tc.Utils.TcType
|
| 33 | 33 | import GHC.Tc.Types.Evidence
|
| 34 | 34 | import GHC.Tc.Types.Origin
|
| 35 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt(..) )
|
|
| 35 | 36 | import GHC.Tc.TyCl.Build
|
| 36 | 37 | |
| 37 | 38 | import GHC.Core.Multiplicity
|
| ... | ... | @@ -22,7 +22,7 @@ module GHC.Tc.Types.BasicTypes ( |
| 22 | 22 | |
| 23 | 23 | import GHC.Prelude
|
| 24 | 24 | |
| 25 | -import GHC.Tc.Types.Origin( UserTypeCtxt )
|
|
| 25 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt )
|
|
| 26 | 26 | import GHC.Tc.Utils.TcType
|
| 27 | 27 | |
| 28 | 28 | import GHC.Types.Id
|
| ... | ... | @@ -120,6 +120,7 @@ import GHC.Types.Var |
| 120 | 120 | import GHC.Tc.Utils.TcType
|
| 121 | 121 | import GHC.Tc.Types.Evidence
|
| 122 | 122 | import GHC.Tc.Types.Origin
|
| 123 | +import GHC.Tc.Types.ErrCtxt
|
|
| 123 | 124 | import GHC.Tc.Types.CtLoc
|
| 124 | 125 | |
| 125 | 126 | import GHC.Builtin.Names
|
| ... | ... | @@ -4,6 +4,11 @@ module GHC.Tc.Types.ErrCtxt |
| 4 | 4 | ( ErrCtxt (..), ErrCtxtMsg(..), CodeSrcFlag (..)
|
| 5 | 5 | , UserSigType(..), FunAppCtxtFunArg(..)
|
| 6 | 6 | , TyConInstFlavour(..)
|
| 7 | + |
|
| 8 | + -- * UserTypeCtxt
|
|
| 9 | + , UserTypeCtxt(..), pprUserTypeCtxt, isSigMaybe
|
|
| 10 | + , ReportRedundantConstraints(..), reportRedundantConstraints
|
|
| 11 | + , redundantConstraintsSpan,
|
|
| 7 | 12 | )
|
| 8 | 13 | where
|
| 9 | 14 | |
| ... | ... | @@ -16,12 +21,12 @@ import GHC.Hs.Extension |
| 16 | 21 | import GHC.Parser.Annotation ( LocatedN, SrcSpanAnnA )
|
| 17 | 22 | |
| 18 | 23 | import GHC.Tc.Errors.Types.PromotionErr ( TermLevelUseCtxt )
|
| 19 | -import {-# SOURCE #-} GHC.Tc.Types.Origin ( CtOrigin, UserTypeCtxt )
|
|
| 20 | -import {-# SOURCE #-} GHC.Tc.Utils.TcType ( TcType, TcTyCon )
|
|
| 24 | +import {-# SOURCE #-} GHC.Tc.Types.Origin ( CtOrigin )
|
|
| 25 | +import GHC.Tc.Utils.TcType ( TcType, TcTyCon, ExpType )
|
|
| 21 | 26 | |
| 22 | 27 | import GHC.Types.Basic ( TyConFlavour )
|
| 23 | 28 | import GHC.Types.Name ( Name )
|
| 24 | -import GHC.Types.SrcLoc ( SrcSpan )
|
|
| 29 | +import GHC.Types.SrcLoc ( SrcSpan, noSrcSpan )
|
|
| 25 | 30 | import GHC.Types.Var ( Id, TyCoVar )
|
| 26 | 31 | |
| 27 | 32 | import GHC.Unit.Types ( Module, InstantiatedModule )
|
| ... | ... | @@ -35,7 +40,7 @@ import GHC.Core.TyCo.Rep ( Type, ThetaType, PredType ) |
| 35 | 40 | import {-# SOURCE #-} GHC.Unit.State ( UnitState ) -- Break the module graph cycle for accesing ErrCtxtMsg in GHC.Hs.Expr
|
| 36 | 41 | |
| 37 | 42 | import GHC.Data.FastString ( FastString )
|
| 38 | -import GHC.Utils.Outputable ( Outputable(..) )
|
|
| 43 | +import GHC.Utils.Outputable
|
|
| 39 | 44 | |
| 40 | 45 | import Language.Haskell.Syntax
|
| 41 | 46 | import Language.Haskell.Syntax.Basic ( FieldLabelString(..) )
|
| ... | ... | @@ -43,6 +48,156 @@ import GHC.Boot.TH.Syntax qualified as TH |
| 43 | 48 | |
| 44 | 49 | import qualified Data.List.NonEmpty as NE
|
| 45 | 50 | |
| 51 | +{- *********************************************************************
|
|
| 52 | +* *
|
|
| 53 | + UserTypeCtxt
|
|
| 54 | +* *
|
|
| 55 | +********************************************************************* -}
|
|
| 56 | + |
|
| 57 | +-------------------------------------
|
|
| 58 | +-- | UserTypeCtxt describes the origin of the polymorphic type
|
|
| 59 | +-- in the places where we need an expression to have that type
|
|
| 60 | +data UserTypeCtxt
|
|
| 61 | + = FunSigCtxt -- Function type signature, when checking the type
|
|
| 62 | + -- Also used for types in SPECIALISE pragmas
|
|
| 63 | + Name -- Name of the function
|
|
| 64 | + ReportRedundantConstraints
|
|
| 65 | + -- See Note [Tracking needed EvIds] in GHC.Tc.Solver
|
|
| 66 | + -- This field is usually 'WantRCC', but 'NoRCC' for
|
|
| 67 | + -- * Record selectors (not important here)
|
|
| 68 | + -- * Class and instance methods. Here the code may legitimately
|
|
| 69 | + -- be more polymorphic than the signature generated from the
|
|
| 70 | + -- class declaration
|
|
| 71 | + -- * Functions whose type signature has hidden the constraints
|
|
| 72 | + -- behind a type synonym. E.g.
|
|
| 73 | + -- type Foo = forall a. Eq a => a -> a
|
|
| 74 | + -- id :: Foo
|
|
| 75 | + -- id x = x
|
|
| 76 | + -- Here we can't give a good location for the redundant constraints
|
|
| 77 | + -- (see lhsSigWcTypeContextSpan), so we don't report redundant
|
|
| 78 | + -- constraints at all. It's not clear that this a good choice;
|
|
| 79 | + -- perhaps we should report, just with a less informative SrcSpan.
|
|
| 80 | + -- c.f. #16154
|
|
| 81 | + |
|
| 82 | + | InfSigCtxt Name -- Inferred type for function
|
|
| 83 | + | ExprSigCtxt -- Expression type signature
|
|
| 84 | + ReportRedundantConstraints
|
|
| 85 | + | KindSigCtxt -- Kind signature
|
|
| 86 | + | StandaloneKindSigCtxt -- Standalone kind signature
|
|
| 87 | + Name -- Name of the type/class
|
|
| 88 | + | TypeAppCtxt -- Visible type application
|
|
| 89 | + | ConArgCtxt Name -- Data constructor argument
|
|
| 90 | + | TySynCtxt Name -- RHS of a type synonym decl
|
|
| 91 | + | PatSynCtxt Name -- Type sig for a pattern synonym
|
|
| 92 | + | PatSigCtxt -- Type sig in pattern
|
|
| 93 | + -- eg f (x::t) = ...
|
|
| 94 | + -- or (x::t, y) = e
|
|
| 95 | + | ForSigCtxt Name -- Foreign import or export signature
|
|
| 96 | + | DefaultDeclCtxt -- Class or types in a default declaration
|
|
| 97 | + | InstDeclCtxt Bool -- An instance declaration
|
|
| 98 | + -- True: stand-alone deriving
|
|
| 99 | + -- False: vanilla instance declaration
|
|
| 100 | + | SpecInstCtxt -- SPECIALISE instance pragma
|
|
| 101 | + | GenSigCtxt -- Higher-rank or impredicative situations
|
|
| 102 | + -- e.g. (f e) where f has a higher-rank type
|
|
| 103 | + -- We might want to elaborate this
|
|
| 104 | + | GhciCtxt Bool -- GHCi command :kind <type>
|
|
| 105 | + -- The Bool indicates if we are checking the outermost
|
|
| 106 | + -- type application.
|
|
| 107 | + -- See Note [Unsaturated type synonyms in GHCi] in
|
|
| 108 | + -- GHC.Tc.Validity.
|
|
| 109 | + |
|
| 110 | + | ClassSCCtxt Name -- Superclasses of a class
|
|
| 111 | + | SigmaCtxt -- Theta part of a normal for-all type
|
|
| 112 | + -- f :: <S> => a -> a
|
|
| 113 | + | DataTyCtxt Name -- The "stupid theta" part of a data decl
|
|
| 114 | + -- data <S> => T a = MkT a
|
|
| 115 | + | DerivClauseCtxt -- A 'deriving' clause
|
|
| 116 | + | TyVarBndrKindCtxt Name -- The kind of a type variable being bound
|
|
| 117 | + | RuleBndrTypeCtxt Name -- The type of a term variable being bound in a RULE
|
|
| 118 | + -- or SPECIALISE pragma
|
|
| 119 | + -- RULE "foo" forall (x :: a -> a). f (Just x) = ...
|
|
| 120 | + | DataKindCtxt Name -- The kind of a data/newtype (instance)
|
|
| 121 | + | TySynKindCtxt Name -- The kind of the RHS of a type synonym
|
|
| 122 | + | TyFamResKindCtxt Name -- The result kind of a type family
|
|
| 123 | + deriving( Eq ) -- Just for checkSkolInfoAnon
|
|
| 124 | + |
|
| 125 | +-- | Report Redundant Constraints.
|
|
| 126 | +data ReportRedundantConstraints
|
|
| 127 | + = NoRRC -- ^ Don't report redundant constraints
|
|
| 128 | + |
|
| 129 | + | WantRRC SrcSpan -- ^ Report redundant constraints
|
|
| 130 | + -- The SrcSpan is for the constraints
|
|
| 131 | + -- E.g. f :: (Eq a, Ord b) => blah
|
|
| 132 | + -- The span is for the (Eq a, Ord b)
|
|
| 133 | + -- We need to record the span here because we have
|
|
| 134 | + -- long since discarded the HsType in favour of a Type
|
|
| 135 | + |
|
| 136 | + deriving( Eq ) -- Just for checkSkolInfoAnon
|
|
| 137 | + |
|
| 138 | +reportRedundantConstraints :: ReportRedundantConstraints -> Bool
|
|
| 139 | +reportRedundantConstraints NoRRC = False
|
|
| 140 | +reportRedundantConstraints (WantRRC {}) = True
|
|
| 141 | + |
|
| 142 | +redundantConstraintsSpan :: UserTypeCtxt -> SrcSpan
|
|
| 143 | +redundantConstraintsSpan (FunSigCtxt _ (WantRRC span)) = span
|
|
| 144 | +redundantConstraintsSpan (ExprSigCtxt (WantRRC span)) = span
|
|
| 145 | +redundantConstraintsSpan _ = noSrcSpan
|
|
| 146 | + |
|
| 147 | +{-
|
|
| 148 | +-- Notes re TySynCtxt
|
|
| 149 | +-- We allow type synonyms that aren't types; e.g. type List = []
|
|
| 150 | +--
|
|
| 151 | +-- If the RHS mentions tyvars that aren't in scope, we'll
|
|
| 152 | +-- quantify over them:
|
|
| 153 | +-- e.g. type T = a->a
|
|
| 154 | +-- will become type T = forall a. a->a
|
|
| 155 | +--
|
|
| 156 | +-- With gla-exts that's right, but for H98 we should complain.
|
|
| 157 | +-}
|
|
| 158 | + |
|
| 159 | + |
|
| 160 | +pprUserTypeCtxt :: UserTypeCtxt -> SDoc
|
|
| 161 | +pprUserTypeCtxt (FunSigCtxt n _) = text "the type signature for" <+> quotes (ppr n)
|
|
| 162 | +pprUserTypeCtxt (InfSigCtxt n) = text "the inferred type for" <+> quotes (ppr n)
|
|
| 163 | +pprUserTypeCtxt (ExprSigCtxt _) = text "an expression type signature"
|
|
| 164 | +pprUserTypeCtxt KindSigCtxt = text "a kind signature"
|
|
| 165 | +pprUserTypeCtxt (StandaloneKindSigCtxt n) = text "a standalone kind signature for" <+> quotes (ppr n)
|
|
| 166 | +pprUserTypeCtxt TypeAppCtxt = text "a type argument"
|
|
| 167 | +pprUserTypeCtxt (ConArgCtxt c) = text "the type of the constructor" <+> quotes (ppr c)
|
|
| 168 | +pprUserTypeCtxt (TySynCtxt c) = text "the RHS of the type synonym" <+> quotes (ppr c)
|
|
| 169 | +pprUserTypeCtxt PatSigCtxt = text "a pattern type signature"
|
|
| 170 | +pprUserTypeCtxt (ForSigCtxt n) = text "the foreign declaration for" <+> quotes (ppr n)
|
|
| 171 | +pprUserTypeCtxt DefaultDeclCtxt = text "a `default' declaration"
|
|
| 172 | +pprUserTypeCtxt (InstDeclCtxt False) = text "an instance declaration"
|
|
| 173 | +pprUserTypeCtxt (InstDeclCtxt True) = text "a stand-alone deriving instance declaration"
|
|
| 174 | +pprUserTypeCtxt SpecInstCtxt = text "a SPECIALISE instance pragma"
|
|
| 175 | +pprUserTypeCtxt GenSigCtxt = text "a type expected by the context"
|
|
| 176 | +pprUserTypeCtxt (GhciCtxt {}) = text "a type in a GHCi command"
|
|
| 177 | +pprUserTypeCtxt (ClassSCCtxt c) = text "the super-classes of class" <+> quotes (ppr c)
|
|
| 178 | +pprUserTypeCtxt SigmaCtxt = text "the context of a polymorphic type"
|
|
| 179 | +pprUserTypeCtxt (DataTyCtxt tc) = text "the context of the data type declaration for" <+> quotes (ppr tc)
|
|
| 180 | +pprUserTypeCtxt (PatSynCtxt n) = text "the signature for pattern synonym" <+> quotes (ppr n)
|
|
| 181 | +pprUserTypeCtxt (DerivClauseCtxt) = text "a `deriving' clause"
|
|
| 182 | +pprUserTypeCtxt (TyVarBndrKindCtxt n) = text "the kind annotation on the type variable" <+> quotes (ppr n)
|
|
| 183 | +pprUserTypeCtxt (RuleBndrTypeCtxt n) = text "the type signature for" <+> quotes (ppr n)
|
|
| 184 | +pprUserTypeCtxt (DataKindCtxt n) = text "the kind annotation on the declaration for" <+> quotes (ppr n)
|
|
| 185 | +pprUserTypeCtxt (TySynKindCtxt n) = text "the kind annotation on the declaration for" <+> quotes (ppr n)
|
|
| 186 | +pprUserTypeCtxt (TyFamResKindCtxt n) = text "the result kind for" <+> quotes (ppr n)
|
|
| 187 | + |
|
| 188 | +isSigMaybe :: UserTypeCtxt -> Maybe Name
|
|
| 189 | +isSigMaybe (FunSigCtxt n _) = Just n
|
|
| 190 | +isSigMaybe (ConArgCtxt n) = Just n
|
|
| 191 | +isSigMaybe (ForSigCtxt n) = Just n
|
|
| 192 | +isSigMaybe (PatSynCtxt n) = Just n
|
|
| 193 | +isSigMaybe _ = Nothing
|
|
| 194 | + |
|
| 195 | + |
|
| 196 | +{- *********************************************************************
|
|
| 197 | +* *
|
|
| 198 | + ErrCtxt
|
|
| 199 | +* *
|
|
| 200 | +********************************************************************* -}
|
|
| 46 | 201 | --------------------------------------------------------------------------------
|
| 47 | 202 | |
| 48 | 203 | -- type ErrCtxtMsgM = TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)
|
| ... | ... | @@ -113,7 +268,7 @@ data ErrCtxtMsg |
| 113 | 268 | -- | In the instance type signature of a class method.
|
| 114 | 269 | | MethSigCtxt !Name !TcType !TcType
|
| 115 | 270 | -- | In a pattern type signature.
|
| 116 | - | PatSigErrCtxt !TcType !TcType
|
|
| 271 | + | PatSigErrCtxt !TcType !ExpType
|
|
| 117 | 272 | -- | In a pattern.
|
| 118 | 273 | | PatCtxt !(Pat GhcRn)
|
| 119 | 274 | -- | In a pattern synonym declaration.
|
| ... | ... | @@ -3,11 +3,6 @@ |
| 3 | 3 | -- | Describes the provenance of types as they flow through the type-checker.
|
| 4 | 4 | -- The datatypes here are mainly used for error message generation.
|
| 5 | 5 | module GHC.Tc.Types.Origin (
|
| 6 | - -- * UserTypeCtxt
|
|
| 7 | - UserTypeCtxt(..), pprUserTypeCtxt, isSigMaybe,
|
|
| 8 | - ReportRedundantConstraints(..), reportRedundantConstraints,
|
|
| 9 | - redundantConstraintsSpan,
|
|
| 10 | - |
|
| 11 | 6 | -- * SkolemInfo, SkolemInfoAnon
|
| 12 | 7 | SkolemInfo(..), SkolemInfoAnon(..), mkSkolemInfo, getSkolemInfo, pprSigSkolInfo, pprSkolInfo,
|
| 13 | 8 | unkSkol, unkSkolAnon, isStaticSkolInfo,
|
| ... | ... | @@ -83,150 +78,6 @@ import qualified Data.Kind as Hs |
| 83 | 78 | import Data.List.NonEmpty (NonEmpty (..))
|
| 84 | 79 | import Data.Maybe (isNothing)
|
| 85 | 80 | |
| 86 | -{- *********************************************************************
|
|
| 87 | -* *
|
|
| 88 | - UserTypeCtxt
|
|
| 89 | -* *
|
|
| 90 | -********************************************************************* -}
|
|
| 91 | - |
|
| 92 | --------------------------------------
|
|
| 93 | --- | UserTypeCtxt describes the origin of the polymorphic type
|
|
| 94 | --- in the places where we need an expression to have that type
|
|
| 95 | -data UserTypeCtxt
|
|
| 96 | - = FunSigCtxt -- Function type signature, when checking the type
|
|
| 97 | - -- Also used for types in SPECIALISE pragmas
|
|
| 98 | - Name -- Name of the function
|
|
| 99 | - ReportRedundantConstraints
|
|
| 100 | - -- See Note [Tracking needed EvIds] in GHC.Tc.Solver
|
|
| 101 | - -- This field is usually 'WantRCC', but 'NoRCC' for
|
|
| 102 | - -- * Record selectors (not important here)
|
|
| 103 | - -- * Class and instance methods. Here the code may legitimately
|
|
| 104 | - -- be more polymorphic than the signature generated from the
|
|
| 105 | - -- class declaration
|
|
| 106 | - -- * Functions whose type signature has hidden the constraints
|
|
| 107 | - -- behind a type synonym. E.g.
|
|
| 108 | - -- type Foo = forall a. Eq a => a -> a
|
|
| 109 | - -- id :: Foo
|
|
| 110 | - -- id x = x
|
|
| 111 | - -- Here we can't give a good location for the redundant constraints
|
|
| 112 | - -- (see lhsSigWcTypeContextSpan), so we don't report redundant
|
|
| 113 | - -- constraints at all. It's not clear that this a good choice;
|
|
| 114 | - -- perhaps we should report, just with a less informative SrcSpan.
|
|
| 115 | - -- c.f. #16154
|
|
| 116 | - |
|
| 117 | - | InfSigCtxt Name -- Inferred type for function
|
|
| 118 | - | ExprSigCtxt -- Expression type signature
|
|
| 119 | - ReportRedundantConstraints
|
|
| 120 | - | KindSigCtxt -- Kind signature
|
|
| 121 | - | StandaloneKindSigCtxt -- Standalone kind signature
|
|
| 122 | - Name -- Name of the type/class
|
|
| 123 | - | TypeAppCtxt -- Visible type application
|
|
| 124 | - | ConArgCtxt Name -- Data constructor argument
|
|
| 125 | - | TySynCtxt Name -- RHS of a type synonym decl
|
|
| 126 | - | PatSynCtxt Name -- Type sig for a pattern synonym
|
|
| 127 | - | PatSigCtxt -- Type sig in pattern
|
|
| 128 | - -- eg f (x::t) = ...
|
|
| 129 | - -- or (x::t, y) = e
|
|
| 130 | - | ForSigCtxt Name -- Foreign import or export signature
|
|
| 131 | - | DefaultDeclCtxt -- Class or types in a default declaration
|
|
| 132 | - | InstDeclCtxt Bool -- An instance declaration
|
|
| 133 | - -- True: stand-alone deriving
|
|
| 134 | - -- False: vanilla instance declaration
|
|
| 135 | - | SpecInstCtxt -- SPECIALISE instance pragma
|
|
| 136 | - | GenSigCtxt -- Higher-rank or impredicative situations
|
|
| 137 | - -- e.g. (f e) where f has a higher-rank type
|
|
| 138 | - -- We might want to elaborate this
|
|
| 139 | - | GhciCtxt Bool -- GHCi command :kind <type>
|
|
| 140 | - -- The Bool indicates if we are checking the outermost
|
|
| 141 | - -- type application.
|
|
| 142 | - -- See Note [Unsaturated type synonyms in GHCi] in
|
|
| 143 | - -- GHC.Tc.Validity.
|
|
| 144 | - |
|
| 145 | - | ClassSCCtxt Name -- Superclasses of a class
|
|
| 146 | - | SigmaCtxt -- Theta part of a normal for-all type
|
|
| 147 | - -- f :: <S> => a -> a
|
|
| 148 | - | DataTyCtxt Name -- The "stupid theta" part of a data decl
|
|
| 149 | - -- data <S> => T a = MkT a
|
|
| 150 | - | DerivClauseCtxt -- A 'deriving' clause
|
|
| 151 | - | TyVarBndrKindCtxt Name -- The kind of a type variable being bound
|
|
| 152 | - | RuleBndrTypeCtxt Name -- The type of a term variable being bound in a RULE
|
|
| 153 | - -- or SPECIALISE pragma
|
|
| 154 | - -- RULE "foo" forall (x :: a -> a). f (Just x) = ...
|
|
| 155 | - | DataKindCtxt Name -- The kind of a data/newtype (instance)
|
|
| 156 | - | TySynKindCtxt Name -- The kind of the RHS of a type synonym
|
|
| 157 | - | TyFamResKindCtxt Name -- The result kind of a type family
|
|
| 158 | - deriving( Eq ) -- Just for checkSkolInfoAnon
|
|
| 159 | - |
|
| 160 | --- | Report Redundant Constraints.
|
|
| 161 | -data ReportRedundantConstraints
|
|
| 162 | - = NoRRC -- ^ Don't report redundant constraints
|
|
| 163 | - |
|
| 164 | - | WantRRC SrcSpan -- ^ Report redundant constraints
|
|
| 165 | - -- The SrcSpan is for the constraints
|
|
| 166 | - -- E.g. f :: (Eq a, Ord b) => blah
|
|
| 167 | - -- The span is for the (Eq a, Ord b)
|
|
| 168 | - -- We need to record the span here because we have
|
|
| 169 | - -- long since discarded the HsType in favour of a Type
|
|
| 170 | - |
|
| 171 | - deriving( Eq ) -- Just for checkSkolInfoAnon
|
|
| 172 | - |
|
| 173 | -reportRedundantConstraints :: ReportRedundantConstraints -> Bool
|
|
| 174 | -reportRedundantConstraints NoRRC = False
|
|
| 175 | -reportRedundantConstraints (WantRRC {}) = True
|
|
| 176 | - |
|
| 177 | -redundantConstraintsSpan :: UserTypeCtxt -> SrcSpan
|
|
| 178 | -redundantConstraintsSpan (FunSigCtxt _ (WantRRC span)) = span
|
|
| 179 | -redundantConstraintsSpan (ExprSigCtxt (WantRRC span)) = span
|
|
| 180 | -redundantConstraintsSpan _ = noSrcSpan
|
|
| 181 | - |
|
| 182 | -{-
|
|
| 183 | --- Notes re TySynCtxt
|
|
| 184 | --- We allow type synonyms that aren't types; e.g. type List = []
|
|
| 185 | ---
|
|
| 186 | --- If the RHS mentions tyvars that aren't in scope, we'll
|
|
| 187 | --- quantify over them:
|
|
| 188 | --- e.g. type T = a->a
|
|
| 189 | --- will become type T = forall a. a->a
|
|
| 190 | ---
|
|
| 191 | --- With gla-exts that's right, but for H98 we should complain.
|
|
| 192 | --}
|
|
| 193 | - |
|
| 194 | - |
|
| 195 | -pprUserTypeCtxt :: UserTypeCtxt -> SDoc
|
|
| 196 | -pprUserTypeCtxt (FunSigCtxt n _) = text "the type signature for" <+> quotes (ppr n)
|
|
| 197 | -pprUserTypeCtxt (InfSigCtxt n) = text "the inferred type for" <+> quotes (ppr n)
|
|
| 198 | -pprUserTypeCtxt (ExprSigCtxt _) = text "an expression type signature"
|
|
| 199 | -pprUserTypeCtxt KindSigCtxt = text "a kind signature"
|
|
| 200 | -pprUserTypeCtxt (StandaloneKindSigCtxt n) = text "a standalone kind signature for" <+> quotes (ppr n)
|
|
| 201 | -pprUserTypeCtxt TypeAppCtxt = text "a type argument"
|
|
| 202 | -pprUserTypeCtxt (ConArgCtxt c) = text "the type of the constructor" <+> quotes (ppr c)
|
|
| 203 | -pprUserTypeCtxt (TySynCtxt c) = text "the RHS of the type synonym" <+> quotes (ppr c)
|
|
| 204 | -pprUserTypeCtxt PatSigCtxt = text "a pattern type signature"
|
|
| 205 | -pprUserTypeCtxt (ForSigCtxt n) = text "the foreign declaration for" <+> quotes (ppr n)
|
|
| 206 | -pprUserTypeCtxt DefaultDeclCtxt = text "a `default' declaration"
|
|
| 207 | -pprUserTypeCtxt (InstDeclCtxt False) = text "an instance declaration"
|
|
| 208 | -pprUserTypeCtxt (InstDeclCtxt True) = text "a stand-alone deriving instance declaration"
|
|
| 209 | -pprUserTypeCtxt SpecInstCtxt = text "a SPECIALISE instance pragma"
|
|
| 210 | -pprUserTypeCtxt GenSigCtxt = text "a type expected by the context"
|
|
| 211 | -pprUserTypeCtxt (GhciCtxt {}) = text "a type in a GHCi command"
|
|
| 212 | -pprUserTypeCtxt (ClassSCCtxt c) = text "the super-classes of class" <+> quotes (ppr c)
|
|
| 213 | -pprUserTypeCtxt SigmaCtxt = text "the context of a polymorphic type"
|
|
| 214 | -pprUserTypeCtxt (DataTyCtxt tc) = text "the context of the data type declaration for" <+> quotes (ppr tc)
|
|
| 215 | -pprUserTypeCtxt (PatSynCtxt n) = text "the signature for pattern synonym" <+> quotes (ppr n)
|
|
| 216 | -pprUserTypeCtxt (DerivClauseCtxt) = text "a `deriving' clause"
|
|
| 217 | -pprUserTypeCtxt (TyVarBndrKindCtxt n) = text "the kind annotation on the type variable" <+> quotes (ppr n)
|
|
| 218 | -pprUserTypeCtxt (RuleBndrTypeCtxt n) = text "the type signature for" <+> quotes (ppr n)
|
|
| 219 | -pprUserTypeCtxt (DataKindCtxt n) = text "the kind annotation on the declaration for" <+> quotes (ppr n)
|
|
| 220 | -pprUserTypeCtxt (TySynKindCtxt n) = text "the kind annotation on the declaration for" <+> quotes (ppr n)
|
|
| 221 | -pprUserTypeCtxt (TyFamResKindCtxt n) = text "the result kind for" <+> quotes (ppr n)
|
|
| 222 | - |
|
| 223 | -isSigMaybe :: UserTypeCtxt -> Maybe Name
|
|
| 224 | -isSigMaybe (FunSigCtxt n _) = Just n
|
|
| 225 | -isSigMaybe (ConArgCtxt n) = Just n
|
|
| 226 | -isSigMaybe (ForSigCtxt n) = Just n
|
|
| 227 | -isSigMaybe (PatSynCtxt n) = Just n
|
|
| 228 | -isSigMaybe _ = Nothing
|
|
| 229 | - |
|
| 230 | 81 | {-
|
| 231 | 82 | ************************************************************************
|
| 232 | 83 | * *
|
| ... | ... | @@ -5,7 +5,6 @@ import GHC.Utils.Misc ( HasDebugCallStack ) |
| 5 | 5 | import {-# SOURCE #-} GHC.Core.TyCo.Rep ( Type )
|
| 6 | 6 | |
| 7 | 7 | data CtOrigin
|
| 8 | -data UserTypeCtxt
|
|
| 9 | 8 | data SkolemInfoAnon
|
| 10 | 9 | data SkolemInfo
|
| 11 | 10 | data FixedRuntimeRepContext
|
| ... | ... | @@ -76,6 +76,8 @@ import GHC.Tc.Types.CtLoc |
| 76 | 76 | , tyConAppRoleExplanation, appTyRoleExplanation
|
| 77 | 77 | )
|
| 78 | 78 | import GHC.Tc.Types.Origin
|
| 79 | +import GHC.Tc.Types.ErrCtxt( UserTypeCtxt(..), ReportRedundantConstraints(..)
|
|
| 80 | + , pprUserTypeCtxt )
|
|
| 79 | 81 | import GHC.Tc.Zonk.TcType
|
| 80 | 82 | import GHC.Tc.Utils.TcMType qualified as TcM
|
| 81 | 83 |
| ... | ... | @@ -26,6 +26,7 @@ import GHC.Tc.Instance.Class ( matchGlobalInst, ClsInstResult(..), AssocInstInfo |
| 26 | 26 | import GHC.Tc.Instance.FunDeps
|
| 27 | 27 | import GHC.Tc.Instance.Family
|
| 28 | 28 | import GHC.Tc.Types.Origin
|
| 29 | +import GHC.Tc.Types.ErrCtxt
|
|
| 29 | 30 | import GHC.Tc.Types.Rank
|
| 30 | 31 | import GHC.Tc.Errors.Types
|
| 31 | 32 | import GHC.Tc.Types.Constraint ( userTypeError_maybe )
|