Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Describes the provenance of types as they flow through the type-checker. The datatypes here are mainly used for error message generation.
Synopsis
- data UserTypeCtxt
- = FunSigCtxt Name ReportRedundantConstraints
- | InfSigCtxt Name
- | ExprSigCtxt ReportRedundantConstraints
- | KindSigCtxt
- | StandaloneKindSigCtxt Name
- | TypeAppCtxt
- | ConArgCtxt Name
- | TySynCtxt Name
- | PatSynCtxt Name
- | PatSigCtxt
- | RuleSigCtxt FastString Name
- | ForSigCtxt Name
- | DefaultDeclCtxt
- | InstDeclCtxt Bool
- | SpecInstCtxt
- | GenSigCtxt
- | GhciCtxt Bool
- | ClassSCCtxt Name
- | SigmaCtxt
- | DataTyCtxt Name
- | DerivClauseCtxt
- | TyVarBndrKindCtxt Name
- | DataKindCtxt Name
- | TySynKindCtxt Name
- | TyFamResKindCtxt Name
- pprUserTypeCtxt :: UserTypeCtxt -> SDoc
- isSigMaybe :: UserTypeCtxt -> Maybe Name
- data ReportRedundantConstraints
- reportRedundantConstraints :: ReportRedundantConstraints -> Bool
- redundantConstraintsSpan :: UserTypeCtxt -> SrcSpan
- data SkolemInfo = SkolemInfo Unique SkolemInfoAnon
- data SkolemInfoAnon
- = SigSkol UserTypeCtxt TcType [(Name, TcTyVar)]
- | SigTypeSkol UserTypeCtxt
- | ForAllSkol TyVarBndrs
- | DerivSkol Type
- | InstSkol
- | FamInstSkol
- | PatSkol ConLike (HsMatchContext GhcTc)
- | IPSkol [HsIPName]
- | RuleSkol RuleName
- | InferSkol [(Name, TcType)]
- | BracketSkol
- | UnifyForAllSkol TcType
- | TyConSkol TyConFlavour Name
- | DataConSkol Name
- | ReifySkol
- | QuantCtxtSkol
- | RuntimeUnkSkol
- | ArrowReboundIfSkol
- | UnkSkol CallStack
- mkSkolemInfo :: MonadIO m => SkolemInfoAnon -> m SkolemInfo
- getSkolemInfo :: SkolemInfo -> SkolemInfoAnon
- pprSigSkolInfo :: UserTypeCtxt -> TcType -> SDoc
- pprSkolInfo :: SkolemInfoAnon -> SDoc
- unkSkol :: HasCallStack => SkolemInfo
- unkSkolAnon :: HasCallStack => SkolemInfoAnon
- data CtOrigin
- = GivenOrigin SkolemInfoAnon
- | InstSCOrigin ScDepth TypeSize
- | OtherSCOrigin ScDepth SkolemInfoAnon
- | OccurrenceOf Name
- | OccurrenceOfRecSel RdrName
- | AppOrigin
- | SpecPragOrigin UserTypeCtxt
- | TypeEqOrigin { }
- | KindEqOrigin TcType TcType CtOrigin (Maybe TypeOrKind)
- | IPOccOrigin HsIPName
- | OverLabelOrigin FastString
- | LiteralOrigin (HsOverLit GhcRn)
- | NegateOrigin
- | ArithSeqOrigin (ArithSeqInfo GhcRn)
- | AssocFamPatOrigin
- | SectionOrigin
- | HasFieldOrigin FastString
- | TupleOrigin
- | ExprSigOrigin
- | PatSigOrigin
- | PatOrigin
- | ProvCtxtOrigin (PatSynBind GhcRn GhcRn)
- | RecordUpdOrigin
- | ViewPatOrigin
- | ScOrigin TypeSize
- | DerivClauseOrigin
- | DerivOriginDC DataCon Int Bool
- | DerivOriginCoerce Id Type Type Bool
- | StandAloneDerivOrigin
- | DefaultOrigin
- | DoOrigin
- | DoPatOrigin (LPat GhcRn)
- | MCompOrigin
- | MCompPatOrigin (LPat GhcRn)
- | ProcOrigin
- | ArrowCmdOrigin
- | AnnOrigin
- | FunDepOrigin1 PredType CtOrigin RealSrcSpan PredType CtOrigin RealSrcSpan
- | FunDepOrigin2 PredType CtOrigin PredType SrcSpan
- | InjTFOrigin1 PredType CtOrigin RealSrcSpan PredType CtOrigin RealSrcSpan
- | ExprHoleOrigin (Maybe OccName)
- | TypeHoleOrigin OccName
- | PatCheckOrigin
- | ListOrigin
- | IfThenElseOrigin
- | BracketOrigin
- | StaticOrigin
- | Shouldn'tHappenOrigin String
- | GhcBug20076
- | InstProvidedOrigin Module ClsInst
- | NonLinearPatternOrigin
- | UsageEnvironmentOf Name
- | CycleBreakerOrigin CtOrigin
- | FRROrigin FixedRuntimeRepOrigin
- | WantedSuperclassOrigin PredType CtOrigin
- | InstanceSigOrigin Name Type Type
- | AmbiguityCheckOrigin UserTypeCtxt
- exprCtOrigin :: HsExpr GhcRn -> CtOrigin
- lexprCtOrigin :: LHsExpr GhcRn -> CtOrigin
- matchesCtOrigin :: MatchGroup GhcRn (LHsExpr GhcRn) -> CtOrigin
- grhssCtOrigin :: GRHSs GhcRn (LHsExpr GhcRn) -> CtOrigin
- isVisibleOrigin :: CtOrigin -> Bool
- toInvisibleOrigin :: CtOrigin -> CtOrigin
- pprCtOrigin :: CtOrigin -> SDoc
- isGivenOrigin :: CtOrigin -> Bool
- isWantedWantedFunDepOrigin :: CtOrigin -> Bool
- isWantedSuperclassOrigin :: CtOrigin -> Bool
- data TypedThing
- data TyVarBndrs = forall flag.OutputableBndrFlag flag 'Renamed => HsTyVarBndrsRn [HsTyVarBndr flag GhcRn]
- isPushCallStackOrigin :: CtOrigin -> Bool
- callStackOriginFS :: CtOrigin -> FastString
- data FixedRuntimeRepOrigin = FixedRuntimeRepOrigin {}
- data FixedRuntimeRepContext
- = FRRRecordUpdate !RdrName !(HsExpr GhcTc)
- | FRRBinder !Name
- | FRRPatBind
- | FRRPatSynArg
- | FRRCase
- | FRRDataConArg !ExprOrPat !DataCon !Int
- | FRRNoBindingResArg !Id !Int
- | FRRTupleArg !Int
- | FRRTupleSection !Int
- | FRRUnboxedSum
- | FRRBodyStmt !StmtOrigin !Int
- | FRRBodyStmtGuard
- | FRRBindStmt !StmtOrigin
- | FRRBindStmtGuard
- | FRRArrow !FRRArrowContext
- | FRRExpectedFunTy !ExpectedFunTyOrigin !Int
- pprFixedRuntimeRepContext :: FixedRuntimeRepContext -> SDoc
- data StmtOrigin
- data FRRArrowContext
- = ArrowCmdResTy !(HsCmd GhcRn)
- | ArrowCmdApp !(HsCmd GhcRn) !(HsExpr GhcRn)
- | ArrowCmdArrApp !(HsExpr GhcRn) !(HsExpr GhcRn) !HsArrAppType
- | ArrowCmdCase
- | ArrowFun !(HsExpr GhcRn)
- pprFRRArrowContext :: FRRArrowContext -> SDoc
- data ExpectedFunTyOrigin
- = ExpectedFunTySyntaxOp !CtOrigin !(HsExpr GhcRn)
- | ExpectedFunTyViewPat !(HsExpr GhcRn)
- | forall (p :: Pass).OutputableBndrId p => ExpectedFunTyArg !TypedThing !(HsExpr (GhcPass p))
- | ExpectedFunTyMatches !TypedThing !(MatchGroup GhcRn (LHsExpr GhcRn))
- | ExpectedFunTyLam !(MatchGroup GhcRn (LHsExpr GhcRn))
- | ExpectedFunTyLamCase LamCaseVariant !(HsExpr GhcRn)
- pprExpectedFunTyOrigin :: ExpectedFunTyOrigin -> Int -> SDoc
- pprExpectedFunTyHerald :: ExpectedFunTyOrigin -> SDoc
UserTypeCtxt
data UserTypeCtxt Source #
UserTypeCtxt describes the origin of the polymorphic type in the places where we need an expression to have that type
Instances
Eq UserTypeCtxt Source # | |
Defined in GHC.Tc.Types.Origin (==) :: UserTypeCtxt -> UserTypeCtxt -> Bool # (/=) :: UserTypeCtxt -> UserTypeCtxt -> Bool # |
pprUserTypeCtxt :: UserTypeCtxt -> SDoc Source #
isSigMaybe :: UserTypeCtxt -> Maybe Name Source #
data ReportRedundantConstraints Source #
Report Redundant Constraints.
NoRRC | Don't report redundant constraints |
WantRRC SrcSpan | Report redundant constraints, and here is the SrcSpan for the constraints E.g. f :: (Eq a, Ord b) => blah The span is for the (Eq a, Ord b) |
Instances
SkolemInfo
data SkolemInfo Source #
SkolemInfo
stores the origin of a skolem type variable,
so that we can display this information to the user in case of a type error.
The Unique
field allows us to report all skolem type variables bound in the
same place in a single report.
SkolemInfo | |
|
Instances
Uniquable SkolemInfo Source # | |
Defined in GHC.Tc.Types.Origin getUnique :: SkolemInfo -> Unique Source # | |
Outputable SkolemInfo Source # | |
Defined in GHC.Tc.Types.Origin ppr :: SkolemInfo -> SDoc Source # |
data SkolemInfoAnon Source #
SkolemInfoAnon
stores the origin of a skolem type variable (e.g. bound by
a user-written forall, the header of a data declaration, a deriving clause, ...).
This information is displayed when reporting an error message, such as
"Couldn't matchk
withl
"
This allows us to explain where the type variable came from.
When several skolem type variables are bound at once, prefer using SkolemInfo
,
which stores a Unique
which allows these type variables to be reported
Instances
Outputable SkolemInfoAnon Source # | |
Defined in GHC.Tc.Types.Origin ppr :: SkolemInfoAnon -> SDoc Source # |
mkSkolemInfo :: MonadIO m => SkolemInfoAnon -> m SkolemInfo Source #
Wrap up the origin of a skolem type variable with a new Unique
,
so that we can common up skolem type variables whose SkolemInfo
shares a certain Unique
.
pprSigSkolInfo :: UserTypeCtxt -> TcType -> SDoc Source #
pprSkolInfo :: SkolemInfoAnon -> SDoc Source #
unkSkol :: HasCallStack => SkolemInfo Source #
Use this when you can't specify a helpful origin for some skolem type variable.
We're hoping to be able to get rid of this entirely, but for the moment it's still needed.
CtOrigin
GivenOrigin SkolemInfoAnon | A given constraint from a user-written type signature. The
|
InstSCOrigin |
|
| |
OtherSCOrigin |
|
| |
OccurrenceOf Name | |
OccurrenceOfRecSel RdrName | |
AppOrigin | |
SpecPragOrigin UserTypeCtxt | |
TypeEqOrigin | |
| |
KindEqOrigin TcType TcType CtOrigin (Maybe TypeOrKind) | |
IPOccOrigin HsIPName | |
OverLabelOrigin FastString | |
LiteralOrigin (HsOverLit GhcRn) | |
NegateOrigin | |
ArithSeqOrigin (ArithSeqInfo GhcRn) | |
AssocFamPatOrigin | |
SectionOrigin | |
HasFieldOrigin FastString | |
TupleOrigin | |
ExprSigOrigin | |
PatSigOrigin | |
PatOrigin | |
ProvCtxtOrigin (PatSynBind GhcRn GhcRn) | |
RecordUpdOrigin | |
ViewPatOrigin | |
ScOrigin TypeSize |
|
DerivClauseOrigin | |
DerivOriginDC DataCon Int Bool | |
DerivOriginCoerce Id Type Type Bool | |
StandAloneDerivOrigin | |
DefaultOrigin | |
DoOrigin | |
DoPatOrigin (LPat GhcRn) | |
MCompOrigin | |
MCompPatOrigin (LPat GhcRn) | |
ProcOrigin | |
ArrowCmdOrigin | |
AnnOrigin | |
FunDepOrigin1 PredType CtOrigin RealSrcSpan PredType CtOrigin RealSrcSpan | |
FunDepOrigin2 PredType CtOrigin PredType SrcSpan | |
InjTFOrigin1 PredType CtOrigin RealSrcSpan PredType CtOrigin RealSrcSpan | |
ExprHoleOrigin (Maybe OccName) | |
TypeHoleOrigin OccName | |
PatCheckOrigin | |
ListOrigin | |
IfThenElseOrigin | |
BracketOrigin | |
StaticOrigin | |
Shouldn'tHappenOrigin String | |
GhcBug20076 | |
InstProvidedOrigin | Testing whether the constraint associated with an instance declaration in a signature file is satisfied upon instantiation. Test cases: backpackshould_failbkpfail{11,43}.bkp |
NonLinearPatternOrigin | |
UsageEnvironmentOf Name | |
CycleBreakerOrigin CtOrigin | |
FRROrigin FixedRuntimeRepOrigin | |
WantedSuperclassOrigin PredType CtOrigin | |
InstanceSigOrigin Name Type Type | |
AmbiguityCheckOrigin UserTypeCtxt |
Instances
matchesCtOrigin :: MatchGroup GhcRn (LHsExpr GhcRn) -> CtOrigin Source #
Extract a suitable CtOrigin from a MatchGroup
grhssCtOrigin :: GRHSs GhcRn (LHsExpr GhcRn) -> CtOrigin Source #
Extract a suitable CtOrigin from guarded RHSs
isVisibleOrigin :: CtOrigin -> Bool Source #
toInvisibleOrigin :: CtOrigin -> CtOrigin Source #
pprCtOrigin :: CtOrigin -> SDoc Source #
isGivenOrigin :: CtOrigin -> Bool Source #
isWantedSuperclassOrigin :: CtOrigin -> Bool Source #
Did a constraint arise from expanding a Wanted constraint to look at superclasses?
data TypedThing Source #
Some thing which has a type.
This datatype is used when we want to report to the user that something has an unexpected type.
Instances
Outputable TypedThing Source # | |
Defined in GHC.Tc.Types.Origin ppr :: TypedThing -> SDoc Source # |
data TyVarBndrs Source #
Some kind of type variable binder.
Used for reporting errors, in SkolemInfo
and TcSolverReportMsg
.
forall flag.OutputableBndrFlag flag 'Renamed => HsTyVarBndrsRn [HsTyVarBndr flag GhcRn] |
Instances
Outputable TyVarBndrs Source # | |
Defined in GHC.Tc.Types.Origin ppr :: TyVarBndrs -> SDoc Source # |
CtOrigin and CallStack
isPushCallStackOrigin :: CtOrigin -> Bool Source #
FixedRuntimeRep origin
data FixedRuntimeRepOrigin Source #
The context for a representation-polymorphism check.
For example, when typechecking (a :: k) -> ...
,
we are checking the type a
because it's the type of
a term variable bound in a lambda, so we use FRRBinder
.
FixedRuntimeRepOrigin | |
|
data FixedRuntimeRepContext Source #
The context in which a representation-polymorphism check was performed.
Does not include the type on which the check was performed; see
FixedRuntimeRepOrigin
for that.
FRRRecordUpdate !RdrName !(HsExpr GhcTc) | Record fields in record updates must have a fixed runtime representation. Test case: RepPolyRecordUpdate. |
FRRBinder !Name | Variable binders must have a fixed runtime representation. Test cases: LevPolyLet, RepPolyPatBind. |
FRRPatBind | Pattern binds must have a fixed runtime representation. Test case: RepPolyInferPatBind. |
FRRPatSynArg | Pattern synonym arguments must have a fixed runtime representation. Test case: RepPolyInferPatSyn. |
FRRCase | The type of the scrutinee in a case statement must have a fixed runtime representation. Test cases: RepPolyCase{1,2}. |
FRRDataConArg !ExprOrPat !DataCon !Int | An instantiation of a newtype/data constructor in which an argument type does not have a fixed runtime representation. The argument can either be an expression or a pattern. Test cases: Expression: UnliftedNewtypesLevityBinder. Pattern: T20363. |
FRRNoBindingResArg !Id !Int | An instantiation of an Test cases: RepPolyWrappedVar, T14561, UnliftedNewtypesCoerceFail. |
FRRTupleArg !Int | Arguments to unboxed tuples must have fixed runtime representations. Test case: RepPolyTuple. |
FRRTupleSection !Int | Tuple sections must have a fixed runtime representation. Test case: RepPolyTupleSection. |
FRRUnboxedSum | Unboxed sums must have a fixed runtime representation. Test cases: RepPolySum. |
FRRBodyStmt !StmtOrigin !Int | The body of a Test cases: RepPolyDoBody{1,2}, RepPolyMcBody. |
FRRBodyStmtGuard | Arguments to a guard in a monad comprehesion must have a fixed runtime representation. Test case: RepPolyMcGuard. |
FRRBindStmt !StmtOrigin | Arguments to Test cases: RepPolyDoBind, RepPolyMcBind. |
FRRBindStmtGuard | A value bound by a pattern guard must have a fixed runtime representation. Test cases: none. |
FRRArrow !FRRArrowContext | A representation-polymorphism check arising from arrow notation. See |
FRRExpectedFunTy | A representation-polymorphic check arising from a call
to See |
|
Instances
Outputable FixedRuntimeRepContext Source # | |
Defined in GHC.Tc.Types.Origin ppr :: FixedRuntimeRepContext -> SDoc Source # |
pprFixedRuntimeRepContext :: FixedRuntimeRepContext -> SDoc Source #
Print the context for a FixedRuntimeRep
representation-polymorphism check.
Note that this function does not include the specific RuntimeRep
which is not fixed. That information is stored in FixedRuntimeRepOrigin
and is reported separately.
data StmtOrigin Source #
Are we in a do
expression or a monad comprehension?
This datatype is only used to report this context to the user in error messages.
Instances
Outputable StmtOrigin Source # | |
Defined in GHC.Tc.Types.Origin ppr :: StmtOrigin -> SDoc Source # |
Arrow command origin
data FRRArrowContext Source #
While typechecking arrow notation, in which context did a representation polymorphism check arise?
See FixedRuntimeRepContext
for more general origins of
representation polymorphism checks.
ArrowCmdResTy !(HsCmd GhcRn) | The result of an arrow command does not have a fixed runtime representation. Test case: RepPolyArrowCmd. |
ArrowCmdApp !(HsCmd GhcRn) !(HsExpr GhcRn) | The argument to an arrow in an arrow command application does not have a fixed runtime representation. Test cases: none. |
ArrowCmdArrApp !(HsExpr GhcRn) !(HsExpr GhcRn) !HsArrAppType | A function in an arrow application does not have a fixed runtime representation. Test cases: none. |
ArrowCmdCase | The scrutinee type in an arrow command case statement does not have a fixed runtime representation. Test cases: none. |
ArrowFun !(HsExpr GhcRn) | The overall type of an arrow proc expression does not have a fixed runtime representation. Test case: RepPolyArrowFun. |
Instances
Outputable FRRArrowContext Source # | |
Defined in GHC.Tc.Types.Origin ppr :: FRRArrowContext -> SDoc Source # |
data ExpectedFunTyOrigin Source #
In what context are we calling matchExpectedFunTys
or matchActualFunTySigma
?
Used for two things:
- Reporting error messages which explain that a function has been
given an unexpected number of arguments.
Uses
pprExpectedFunTyHerald
. See Note [Herald for matchExpectedFunTys] in GHC.Tc.Utils.Unify. - Reporting representation-polymorphism errors when a function argument
doesn't have a fixed RuntimeRep as per Note [Fixed RuntimeRep]
in GHC.Tc.Utils.Concrete.
Uses
pprExpectedFunTyOrigin
. SeeFixedRuntimeRepContext
for the situations in which representation-polymorphism checks are performed.
ExpectedFunTySyntaxOp | A rebindable syntax operator is expected to have a function type. Test cases for representation-polymorphism checks: RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK |
ExpectedFunTyViewPat | A view pattern must have a function type. Test cases for representation-polymorphism checks: RepPolyBinder |
forall (p :: Pass).OutputableBndrId p => ExpectedFunTyArg | Need to be able to extract an argument type from a function type. Test cases for representation-polymorphism checks: RepPolyApp |
| |
ExpectedFunTyMatches | Ensure that a function defined by equations indeed has a function type with the appropriate number of arguments. Test cases for representation-polymorphism checks: RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern |
| |
ExpectedFunTyLam !(MatchGroup GhcRn (LHsExpr GhcRn)) | Ensure that a lambda abstraction has a function type. Test cases for representation-polymorphism checks: RepPolyLambda |
ExpectedFunTyLamCase | Ensure that a lambda case expression has a function type. Test cases for representation-polymorphism checks: RepPolyMatch |
|
pprExpectedFunTyOrigin Source #
:: ExpectedFunTyOrigin | |
-> Int | argument position (starting at 1) |
-> SDoc |