IfGblEnv(..), IfLclEnv(..),
-- Ranamer types
- ErrCtxt,
+ ErrCtxt, RecFieldEnv,
ImportAvails(..), emptyImportAvails, plusImportAvails,
WhereFrom(..), mkModDeps,
-- Typechecker types
- TcTyThing(..), pprTcTyThingCategory,
+ TcTyThing(..), pprTcTyThingCategory, RefinementVisibility(..),
-- Template Haskell
ThStage(..), topStage, topSpliceStage,
plusLIEs, mkLIE, isEmptyLIE, lieToList, listToLIE,
-- Misc other types
- TcId, TcIdSet, TcDictBinds
+ TcId, TcIdSet, TcDictBinds,
+
) where
#include "HsVersions.h"
import HscTypes
import Packages
import Type
+import Coercion
import TcType
import TcGadt
import InstEnv
import Bag
import Outputable
import ListSetOps
+import FiniteMap
import Data.Maybe
import Data.List
env_gbl :: gbl, -- Info about things defined at the top level
-- of the module being compiled
- env_lcl :: lcl -- Nested stuff; changes as we go into
- -- an expression
+ env_lcl :: lcl -- Nested stuff; changes as we go into
}
-- TcGblEnv describes the top-level of the module at the
tcg_default :: Maybe [Type], -- Types used for defaulting
-- Nothing => no 'default' decl
- tcg_fix_env :: FixityEnv, -- Just for things in this module
+ tcg_fix_env :: FixityEnv, -- Just for things in this module
+ tcg_field_env :: RecFieldEnv, -- Just for things in this module
tcg_type_env :: TypeEnv, -- Global type env for the module we are compiling now
-- All TyCons and Classes (for this module) end up in here right away,
tcg_fords :: [LForeignDecl Id], -- ...Foreign import & exports
tcg_doc :: Maybe (HsDoc Name), -- Maybe Haddock documentation
- tcg_hmi :: HaddockModInfo Name -- Haddock module information
+ tcg_hmi :: HaddockModInfo Name, -- Haddock module information
+ tcg_hpc :: AnyHpcUsage -- True if any part of the prog uses hpc instrumentation.
}
+
+type RecFieldEnv = NameEnv [Name] -- Maps a constructor name *in this module*
+ -- to the fields for that constructor
+ -- This is used when dealing with ".." notation in record
+ -- construction and pattern matching.
+ -- The FieldEnv deals *only* with constructors defined in
+ -- *thie* module. For imported modules, we get the same info
+ -- from the TypeEnv
\end{code}
%************************************************************************
| ATcId { -- Ids defined in this module; may not be fully zonked
tct_id :: TcId,
- tct_co :: Maybe HsWrapper, -- Nothing <=> Do not apply a GADT type refinement
+ tct_co :: RefinementVisibility, -- Previously: Maybe HsWrapper
+ -- Nothing <=> Do not apply a GADT type refinement
-- I am wobbly, or have no free
-- type variables
-- Just co <=> Apply any type refinement to me,
| AThing TcKind -- Used temporarily, during kind checking, for the
-- tycons and clases in this recursive group
+data RefinementVisibility
+ = Unrefineable -- Do not apply a GADT refinement
+ -- I have no free variables
+
+ | Rigid HsWrapper -- Apply any refinement to me
+ -- and record it in the coercion
+
+ | Wobbly -- Do not apply a GADT refinement
+ -- I am wobbly
+
+ | WobblyInvisible -- Wobbly type, not available inside current
+ -- GADT refinement
+
instance Outputable TcTyThing where -- Debugging only
ppr (AGlobal g) = ppr g
ppr elt@(ATcId {}) = text "Identifier" <>
pprTcTyThingCategory (ATyVar {}) = ptext SLIT("Type variable")
pprTcTyThingCategory (ATcId {}) = ptext SLIT("Local identifier")
pprTcTyThingCategory (AThing {}) = ptext SLIT("Kinded thing")
+
+instance Outputable RefinementVisibility where
+ ppr Unrefineable = ptext SLIT("unrefineable")
+ ppr (Rigid co) = ptext SLIT("rigid") <+> ppr co
+ ppr Wobbly = ptext SLIT("wobbly")
+ ppr WobblyInvisible = ptext SLIT("wobbly-invisible")
+
\end{code}
\begin{code}
\begin{code}
data ImportAvails
= ImportAvails {
- imp_mods :: ModuleEnv (Module, Bool, SrcSpan),
+ imp_mods :: ModuleEnv (Module, [(ModuleName, Bool, SrcSpan)]),
-- Domain is all directly-imported modules
+ -- The ModuleName is what the module was imported as, e.g. in
+ -- import Foo as Bar
+ -- it is Bar.
-- Bool means:
-- True => import was "import Foo ()"
-- False => import was some other form
(ImportAvails { imp_mods = mods2,
imp_dep_mods = dmods2, imp_dep_pkgs = dpkgs2,
imp_orphs = orphs2, imp_finsts = finsts2 })
- = ImportAvails { imp_mods = mods1 `plusModuleEnv` mods2,
+ = ImportAvails { imp_mods = plusModuleEnv_C plus_mod mods1 mods2,
imp_dep_mods = plusUFM_C plus_mod_dep dmods1 dmods2,
imp_dep_pkgs = dpkgs1 `unionLists` dpkgs2,
imp_orphs = orphs1 `unionLists` orphs2,
imp_finsts = finsts1 `unionLists` finsts2 }
where
+ plus_mod (m1, xs1) (_, xs2) = (m1, xs1 ++ xs2)
plus_mod_dep (m1, boot1) (m2, boot2)
= WARN( not (m1 == m2), (ppr m1 <+> ppr m2) $$ (ppr boot1 <+> ppr boot2) )
-- Check mod-names match
Method 34 doubleId [Int] origin
+In addition to the basic Haskell variants of 'Inst's, they can now also
+represent implication constraints 'forall tvs. (reft, given) => wanted'
+and equality constraints 'co :: ty1 ~ ty2'.
+
\begin{code}
data Inst
= Dict {
tci_ty :: TcType, -- The type at which the literal is used
tci_loc :: InstLoc
}
+
+ | EqInst { -- delayed unification of the form
+ -- co :: ty1 ~ ty2
+ tci_left :: TcType, -- ty1
+ tci_right :: TcType, -- ty2
+ tci_co :: Either -- co
+ TcTyVar -- a wanted equation, with a hole, to be
+ -- filled with a witness for the equality
+ -- for equation generated by the
+ -- unifier, 'ty1' is the actual and
+ -- 'ty2' the expected type
+ Coercion, -- a given equation, with a coercion
+ -- witnessing the equality
+ -- a coercion that originates from a
+ -- signature or a GADT is a CoVar, but
+ -- after normalisation of coercions,
+ -- they can be arbitrary Coercions
+ -- involving constructors and
+ -- pseudo-constructors like sym and
+ -- trans.
+ tci_loc :: InstLoc,
+
+ tci_name :: Name -- Debugging help only: this makes it easier to
+ -- follow where a constraint is used in a morass
+ -- of trace messages! Unlike other Insts, it has
+ -- no semantic significance whatsoever.
+ }
\end{code}
@Insts@ are ordered by their class/type info, rather than by their
cmpInst (ImplicInst {}) (Method {}) = GT
cmpInst (ImplicInst {}) (LitInst {}) = GT
cmpInst i1@(ImplicInst {}) i2@(ImplicInst {}) = tci_name i1 `compare` tci_name i2
+cmpInst (ImplicInst {}) other = LT
+
+ -- same for Equality constraints
+cmpInst (EqInst {}) (Dict {}) = GT
+cmpInst (EqInst {}) (Method {}) = GT
+cmpInst (EqInst {}) (LitInst {}) = GT
+cmpInst (EqInst {}) (ImplicInst {}) = GT
+cmpInst i1@(EqInst {}) i2@(EqInst {}) = tci_name i1 `compare` tci_name i2
\end{code}
| DoOrigin -- Arising from a do expression
| ProcOrigin -- Arising from a proc expression
| ImplicOrigin SDoc -- An implication constraint
+ | EqOrigin -- A type equality
instance Outputable InstOrigin where
ppr (OccurrenceOf name) = hsep [ptext SLIT("a use of"), quotes (ppr name)]
ppr ProcOrigin = ptext SLIT("a proc expression")
ppr (ImplicOrigin doc) = doc
ppr (SigOrigin info) = pprSkolInfo info
+ ppr EqOrigin = ptext SLIT("a type equality")
+
\end{code}