summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2021-12-31 12:31:47 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-12-31 12:32:32 +0000
commit2adf111f8d015453662ff2bdb0239601f9181716 (patch)
treea99181628b91d28a9c9a165a8b60837418a0ebf1
parent3ca3ea1f9a8f56e8a03660e20b10221b2577f72e (diff)
downloadhaskell-2adf111f8d015453662ff2bdb0239601f9181716.tar.gz
Apply 13 suggestion(s) to 3 file(s)
-rw-r--r--compiler/GHC/Tc/Gen/HsType.hs4
-rw-r--r--compiler/GHC/Tc/TyCl.hs14
-rw-r--r--compiler/GHC/Tc/Types/Origin.hs32
3 files changed, 37 insertions, 13 deletions
diff --git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs
index 96730dadbc..11d9ffede3 100644
--- a/compiler/GHC/Tc/Gen/HsType.hs
+++ b/compiler/GHC/Tc/Gen/HsType.hs
@@ -3005,12 +3005,12 @@ these first.
********************************************************************* -}
-- | Describes the kind expected in a certain context.
-data ContextKind = TheKind Kind -- ^ a specific kind
+data ContextKind = TheKind TcKind -- ^ a specific kind
| AnyKind -- ^ any kind will do
| OpenKind -- ^ something of the form @TYPE _@
-----------------------
-newExpectedKind :: ContextKind -> TcM Kind
+newExpectedKind :: ContextKind -> TcM TcKind
newExpectedKind (TheKind k) = return k
newExpectedKind AnyKind = newMetaKindVar
newExpectedKind OpenKind = newOpenTypeKind
diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs
index af7664d767..d511834f18 100644
--- a/compiler/GHC/Tc/TyCl.hs
+++ b/compiler/GHC/Tc/TyCl.hs
@@ -1581,7 +1581,7 @@ kcTyClDecl :: TyClDecl GhcRn -> TcTyCon -> TcM ()
-- TcTyVars rather than create skolemised variables for the bound variables.
-- - inferInitialKinds makes the TcTyCon where the tyvars are TcTyVars
-- - In this function, those TcTyVars are unified with other kind variables during
--- - kind inference (see [How TcTyCons work])
+-- kind inference (see [How TcTyCons work])
kcTyClDecl (DataDecl { tcdLName = (L _ _name), tcdDataDefn = defn }) tycon
| HsDataDefn { dd_ctxt = ctxt, dd_cons = cons, dd_ND = new_or_data } <- defn
@@ -1624,7 +1624,7 @@ kcTyClDecl (FamDecl _ (FamilyDecl { fdInfo = fd_info })) fam_tc
-- This includes doing kind unification if the type is a newtype.
-- See Note [Implementation of UnliftedNewtypes] for why we need
-- the first two arguments.
-kcConArgTys :: NewOrData -> Kind -> [HsScaled GhcRn (LHsType GhcRn)] -> TcM ()
+kcConArgTys :: NewOrData -> TcKind -> [HsScaled GhcRn (LHsType GhcRn)] -> TcM ()
kcConArgTys new_or_data res_kind arg_tys = do
{ let exp_kind = getArgExpKind new_or_data res_kind
; forM_ arg_tys (\(HsScaled mult ty) -> do _ <- tcCheckLHsType (getBangType ty) exp_kind
@@ -1633,7 +1633,7 @@ kcConArgTys new_or_data res_kind arg_tys = do
}
-- Kind-check the types of arguments to a Haskell98 data constructor.
-kcConH98Args :: NewOrData -> Kind -> HsConDeclH98Details GhcRn -> TcM ()
+kcConH98Args :: NewOrData -> TcKind -> HsConDeclH98Details GhcRn -> TcM ()
kcConH98Args new_or_data res_kind con_args = case con_args of
PrefixCon _ tys -> kcConArgTys new_or_data res_kind tys
InfixCon ty1 ty2 -> kcConArgTys new_or_data res_kind [ty1, ty2]
@@ -1641,14 +1641,14 @@ kcConH98Args new_or_data res_kind con_args = case con_args of
map (hsLinear . cd_fld_type . unLoc) flds
-- Kind-check the types of arguments to a GADT data constructor.
-kcConGADTArgs :: NewOrData -> Kind -> HsConDeclGADTDetails GhcRn -> TcM ()
+kcConGADTArgs :: NewOrData -> TcKind -> HsConDeclGADTDetails GhcRn -> TcM ()
kcConGADTArgs new_or_data res_kind con_args = case con_args of
PrefixConGADT tys -> kcConArgTys new_or_data res_kind tys
RecConGADT (L _ flds) _ -> kcConArgTys new_or_data res_kind $
map (hsLinear . cd_fld_type . unLoc) flds
kcConDecls :: NewOrData
- -> Kind -- The result kind signature
+ -> TcKind -- The result kind signature
-- Used only in H98 case
-> [LConDecl GhcRn] -- The data constructors
-> TcM ()
@@ -1662,7 +1662,7 @@ kcConDecls new_or_data tc_res_kind cons
-- this type. See Note [Implementation of UnliftedNewtypes] for why
-- we need the first two arguments.
kcConDecl :: NewOrData
- -> Kind -- Result kind of the type constructor
+ -> TcKind -- Result kind of the type constructor
-- Usually Type but can be TYPE UnliftedRep
-- or even TYPE r, in the case of unlifted newtype
-- Used only in H98 case
@@ -3663,7 +3663,7 @@ tcInferLHsTypeKind doesn't any gratuitous top-level casts.
-- it is OpenKind for datatypes and liftedTypeKind.
-- Why do we not check for -XUnliftedNewtypes? See point <Error Messages>
-- in Note [Implementation of UnliftedNewtypes]
-getArgExpKind :: NewOrData -> Kind -> ContextKind
+getArgExpKind :: NewOrData -> TcKind -> ContextKind
getArgExpKind NewType res_ki = TheKind res_ki
getArgExpKind DataType _ = OpenKind
diff --git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs
index 5e3bdc5a4e..64a6a04466 100644
--- a/compiler/GHC/Tc/Types/Origin.hs
+++ b/compiler/GHC/Tc/Types/Origin.hs
@@ -196,14 +196,30 @@ isSigMaybe _ = Nothing
************************************************************************
-}
-data SkolemInfo = SkolemInfo Unique SkolemInfoAnon
+-- | '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.
+data SkolemInfo
+ = SkolemInfo
+ Unique -- ^ used to common up skolem variables bound at the same location
+ SkolemInfoAnon -- ^ the information about the origin of the skolem type variable
instance Uniquable SkolemInfo where
getUnique (SkolemInfo u _) = u
--- SkolemInfo gives the origin of *given* constraints
--- a) type variables are skolemised
--- b) an implication constraint is generated
+-- | '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 match 'k' with 'l'"@
+--
+-- 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
data SkolemInfoAnon
= SigSkol -- A skolem that is created by instantiating
-- a programmer-supplied type signature
@@ -269,9 +285,17 @@ data SkolemInfoAnon
+-- | 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.
unkSkol :: HasCallStack => SkolemInfo
unkSkol = SkolemInfo (mkUniqueGrimily 0) (UnkSkol callStack)
+-- | 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'.
mkSkolemInfo :: MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo sk_anon = do
u <- liftIO $! uniqFromMask 's'