-@mkInstSpecEnv@ is used to construct the @SpecEnv@ for a dfun.
-It does it by filtering the class's @InstEnv@. All pretty shady stuff.
-
-\begin{code}
-mkInstSpecEnv clas inst_ty inst_tvs inst_theta = panic "mkInstSpecEnv"
-\end{code}
-
-\begin{pseudocode}
-mkInstSpecEnv :: Class -- class
- -> Type -- instance type
- -> [TyVarTemplate] -- instance tyvars
- -> ThetaType -- superclasses dicts
- -> SpecEnv -- specenv for dfun of instance
-
-mkInstSpecEnv clas inst_ty inst_tvs inst_theta
- = mkSpecEnv (catMaybes (map maybe_spec_info matches))
- where
- matches = matchMEnv matchTy (classInstEnv clas) inst_ty
-
- maybe_spec_info (_, match_info, MkInstTemplate dfun _ [])
- = Just (SpecInfo (map (assocMaybe match_info) inst_tvs) (length inst_theta) dfun)
- maybe_spec_info (_, match_info, _)
- = Nothing
-\end{pseudocode}
-
-
-\begin{code}
-addClassInst
- :: ClassInstEnv -- Incoming envt
- -> Type -- The instance type: inst_ty
- -> Id -- Dict fun id to apply. Free tyvars of inst_ty must
- -- be the same as the forall'd tyvars of the dfun id.
- -> MaybeErr
- ClassInstEnv -- Success
- (Type, Id) -- Offending overlap
-
-addClassInst inst_env inst_ty dfun_id = insertMEnv matchTy inst_env inst_ty dfun_id
-\end{code}
-
-
-
-%************************************************************************
-%* *
-\subsection[Inst-origin]{The @InstOrigin@ type}
-%* *
-%************************************************************************
-
-The @InstOrigin@ type gives information about where a dictionary came from.
-This is important for decent error message reporting because dictionaries
-don't appear in the original source code. Doubtless this type will evolve...
-
-\begin{code}
-data InstOrigin s
- = OccurrenceOf (TcIdOcc s) -- Occurrence of an overloaded identifier
- | OccurrenceOfCon Id -- Occurrence of a data constructor
-
- | RecordUpdOrigin
-
- | DataDeclOrigin -- Typechecking a data declaration
-
- | InstanceDeclOrigin -- Typechecking an instance decl
-
- | LiteralOrigin HsLit -- Occurrence of a literal
-
- | ArithSeqOrigin RenamedArithSeqInfo -- [x..], [x..y] etc
-
- | SignatureOrigin -- A dict created from a type signature
-
- | DoOrigin -- The monad for a do expression
-
- | ClassDeclOrigin -- Manufactured during a class decl
-
--- NO MORE!
--- | DerivingOrigin InstanceMapper
--- Class
--- TyCon
-
- -- During "deriving" operations we have an ever changing
- -- mapping of classes to instances, so we record it inside the
- -- origin information. This is a bit of a hack, but it works
- -- fine. (Simon is to blame [WDP].)
-
- | InstanceSpecOrigin InstanceMapper
- Class -- in a SPECIALIZE instance pragma
- Type
-
- -- When specialising instances the instance info attached to
- -- each class is not yet ready, so we record it inside the
- -- origin information. This is a bit of a hack, but it works
- -- fine. (Patrick is to blame [WDP].)
-
--- | DefaultDeclOrigin -- Related to a `default' declaration
-
- | ValSpecOrigin Name -- in a SPECIALIZE pragma for a value
-
- -- Argument or result of a ccall
- -- Dictionaries with this origin aren't actually mentioned in the
- -- translated term, and so need not be bound. Nor should they
- -- be abstracted over.
-
- | CCallOrigin String -- CCall label
- (Maybe RenamedHsExpr) -- Nothing if it's the result
- -- Just arg, for an argument
-
- | LitLitOrigin String -- the litlit
-
- | UnknownOrigin -- Help! I give up...
-\end{code}
-
-\begin{code}
--- During deriving and instance specialisation operations
--- we can't get the instances of the class from inside the
--- class, because the latter ain't ready yet. Instead we
--- find a mapping from classes to envts inside the dict origin.
-
-get_inst_env :: Class -> InstOrigin s -> ClassInstEnv
--- get_inst_env clas (DerivingOrigin inst_mapper _ _)
--- = fst (inst_mapper clas)
-get_inst_env clas (InstanceSpecOrigin inst_mapper _ _)
- = fst (inst_mapper clas)
-get_inst_env clas other_orig = classInstEnv clas
-
-
-pprOrigin :: String -> InstOrigin s -> SrcLoc -> Error
-
-pprOrigin hdr orig locn
- = addErrLoc locn hdr $ \ sty ->
- case orig of
- OccurrenceOf id ->
- ppBesides [ppPStr SLIT("at a use of an overloaded identifier: `"),
- ppr sty id, ppChar '\'']
- OccurrenceOfCon id ->
- ppBesides [ppPStr SLIT("at a use of an overloaded constructor: `"),
- ppr sty id, ppChar '\'']
- InstanceDeclOrigin ->
- ppStr "in an instance declaration"
- LiteralOrigin lit ->
- ppCat [ppStr "at an overloaded literal:", ppr sty lit]
- ArithSeqOrigin seq ->
- ppCat [ppStr "at an arithmetic sequence:", ppr sty seq]
- SignatureOrigin ->
- ppStr "in a type signature"
- DoOrigin ->
- ppStr "in a do statement"
- ClassDeclOrigin ->
- ppStr "in a class declaration"
- InstanceSpecOrigin _ clas ty ->
- ppBesides [ppStr "in a SPECIALIZE instance pragma; class \"",
- ppr sty clas, ppStr "\" type: ", ppr sty ty]
- ValSpecOrigin name ->
- ppBesides [ppStr "in a SPECIALIZE user-pragma for `",
- ppr sty name, ppStr "'"]
- CCallOrigin clabel Nothing{-ccall result-} ->
- ppBesides [ppStr "in the result of the _ccall_ to `",
- ppStr clabel, ppStr "'"]
- CCallOrigin clabel (Just arg_expr) ->
- ppBesides [ppStr "in an argument in the _ccall_ to `",
- ppStr clabel, ppStr "', namely: ", ppr sty arg_expr]
- LitLitOrigin s ->
- ppBesides [ppStr "in this ``literal-literal'': ", ppStr s]
- UnknownOrigin ->
- ppStr "in... oops -- I don't know where the overloading came from!"