[project @ 1998-04-29 09:06:09 by sof]
[ghc-hetmet.git] / ghc / compiler / coreSyn / CoreLint.lhs
index f42a49e..62868f6 100644 (file)
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1993-1995
+% (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
 %
 \section[CoreLint]{A ``lint'' pass to check for Core correctness}
 
 \begin{code}
-#include "HsVersions.h"
-
 module CoreLint (
        lintCoreBindings,
-       lintUnfolding,
-       
-       PprStyle, CoreBinding, PlainCoreBinding(..), Id
+       lintUnfolding
     ) where
 
-IMPORT_Trace
+#include "HsVersions.h"
+
+import IO      ( hPutStr, stderr )
+
+import CmdLineOpts      ( opt_D_show_passes, opt_DoCoreLinting )
+import CoreSyn
 
-import AbsPrel         ( typeOfPrimOp, mkFunTy, PrimOp(..), PrimKind
-                         IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
-                         IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
-                       )
-import AbsUniType
 import Bag
-import BasicLit                ( typeOfBasicLit, BasicLit )
-import CoreSyn         ( pprCoreBinding ) -- ToDo: correctly
-import Id              ( getIdUniType, isNullaryDataCon, isBottomingId,
-                         getInstantiatedDataConSig, Id
-                         IF_ATTACK_PRAGMAS(COMMA bottomIsGuaranteed)
+import Kind            ( hasMoreBoxityInfo, Kind{-instance-} )
+import Literal         ( literalType, Literal{-instance-} )
+import Id              ( idType, isBottomingId, dataConRepType, isDataCon, isAlgCon,
+                         dataConArgTys, GenId{-instances-},
+                         emptyIdSet, mkIdSet,
+                         unionIdSets, elementOfIdSet, IdSet,
+                         Id
                        )
-import Maybes
-import Outputable
-import PlainCore
-import Pretty
+import Maybes          ( catMaybes )
+import Name            ( isLocallyDefined, getSrcLoc, Name{-instance NamedThing-},
+                         NamedThing(..)
+                       )
+import PprCore
+import ErrUtils                ( doIfSet, ghcExit )
+import PrimOp          ( primOpType )
+import PrimRep         ( PrimRep(..) )
+import Specialise       ( idSpecVars )
 import SrcLoc          ( SrcLoc )
-import UniqSet
-import Util
+import Type            ( mkFunTy, splitFunTy_maybe, mkForAllTy,
+                         splitForAllTy_maybe,
+                         isUnpointedType, typeKind, instantiateTy,
+                         splitAlgTyConApp_maybe, Type
+                       )
+import TyCon           ( TyCon, isPrimTyCon, isDataTyCon )
+import TyVar           ( TyVar, tyVarKind, mkTyVarEnv )
+import ErrUtils                ( ErrMsg )
+import Unique          ( Unique )
+import Util            ( zipEqual )
+import Outputable
 
-infixr 9 `thenL`, `thenL_`, `thenMaybeL`, `thenMaybeL_`
+infixr 9 `thenL`, `seqL`, `thenMaybeL`
 \end{code}
 
-Checks for 
-       (a) type errors
-       (b) locally-defined variables used but not defined
-
-Doesn't check for out-of-scope type variables, because they can
-legitimately arise.  Eg
-\begin{verbatim}
-       k = /\a b -> \x::a y::b -> x
-       f = /\c -> \z::c -> k c w z (error w "foo")
-\end{verbatim}
-Here \tr{w} is just a free type variable.
-
 %************************************************************************
 %*                                                                     *
-\subsection{``lint'' for various constructs}
+\subsection[lintCoreBindings]{@lintCoreBindings@: Top-level interface}
 %*                                                                     *
 %************************************************************************
 
-@lintCoreBindings@ is the top-level interface function.
+Checks that a set of core bindings is well-formed.  The PprStyle and String
+just control what we print in the event of an error.  The Bool value
+indicates whether we have done any specialisation yet (in which case we do
+some extra checks).
+
+We check for
+       (a) type errors
+       (b) Out-of-scope type variables
+       (c) Out-of-scope local variables
+       (d) Ill-kinded types
+
+If we have done specialisation the we check that there are
+       (a) No top-level bindings of primitive (unboxed type)
+
+Outstanding issues:
+
+    --
+    -- Things are *not* OK if:
+    --
+    -- * Unsaturated type app before specialisation has been done;
+    --
+    -- * Oversaturated type app after specialisation (eta reduction
+    --   may well be happening...);
+    --
+    -- Note: checkTyApp is usually followed by a call to checkSpecTyApp.
+    --
 
 \begin{code}
-lintCoreBindings :: PprStyle -> String -> Bool -> [PlainCoreBinding] -> [PlainCoreBinding]
-
-lintCoreBindings sty whodunnit spec_done binds
-  = BSCC("CoreLint")
-    case (initL (lint_binds binds) spec_done) of
-      Nothing  -> binds
-      Just msg -> pprPanic "" (ppAboves [
-                       ppStr ("*** Core Lint Errors: in "++whodunnit++" ***"),
-                       msg sty,
-                       ppStr "*** Offending Program ***",
-                       ppAboves (map (pprCoreBinding sty pprBigCoreBinder pprTypedCoreBinder ppr) binds),
-                       ppStr "*** End of Offense ***"])
-    ESCC
-  where
-    lint_binds :: [PlainCoreBinding] -> LintM ()
+lintCoreBindings :: String -> Bool -> [CoreBinding] -> IO ()
+
+lintCoreBindings whoDunnit spec_done binds
+  | not opt_DoCoreLinting
+  = return ()
+
+lintCoreBindings whoDunnit spec_done binds
+  = case (initL (lint_binds binds) spec_done) of
+      Nothing       -> doIfSet opt_D_show_passes
+                       (hPutStr stderr ("*** Core Linted result of " ++ whoDunnit ++ "\n"))
 
+      Just bad_news -> printDump (display bad_news)    >>
+                      ghcExit 1
+  where
     lint_binds [] = returnL ()
-    lint_binds (bind:binds) 
-      = lintCoreBinds bind             `thenL` \ binders ->
-       addInScopeVars binders (
-           lint_binds binds
-       )
+    lint_binds (bind:binds)
+      = lintCoreBinding bind `thenL` \binders ->
+       addInScopeVars binders (lint_binds binds)
+
+    display bad_news
+      = vcat [
+               text ("*** Core Lint Errors: in result of " ++ whoDunnit ++ " ***"),
+               bad_news,
+               ptext SLIT("*** Offending Program ***"),
+               pprCoreBindings binds,
+               ptext SLIT("*** End of Offense ***")
+       ]
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsection[lintUnfolding]{lintUnfolding}
+%*                                                                     *
+%************************************************************************
+
 We use this to check all unfoldings that come in from interfaces
 (it is very painful to catch errors otherwise):
+
 \begin{code}
-lintUnfolding :: SrcLoc -> PlainCoreExpr -> PlainCoreExpr
+lintUnfolding :: SrcLoc -> CoreExpr -> Maybe CoreExpr
 
 lintUnfolding locn expr
-  = case (initL (addLoc (ImportedUnfolding locn) (lintCoreExpr expr)) True{-pretend spec done-}) of
-      Nothing  -> expr
-      Just msg -> error ("ERROR: Type-incorrect unfolding from an interface:\n"++
-                       (ppShow 80 (ppAboves [msg PprForUser,
-                                       ppStr "*** Bad unfolding ***",
-                                       ppr PprDebug expr,
-                                       ppStr "*** End of bad unfolding ***"]))) 
+  = case
+      (initL (addLoc (ImportedUnfolding locn) (lintCoreExpr expr))
+       True{-pretend spec done-})
+    of
+      Nothing  -> Just expr
+      Just msg ->
+        pprTrace "WARNING: Discarded bad unfolding from interface:\n"
+       (vcat [msg,
+                  ptext SLIT("*** Bad unfolding ***"),
+                  ppr expr,
+                  ptext SLIT("*** End unfolding ***")])
+       Nothing
 \end{code}
 
-\begin{code}
-lintCoreAtom :: PlainCoreAtom -> LintM (Maybe UniType)
+%************************************************************************
+%*                                                                     *
+\subsection[lintCoreBinding]{lintCoreBinding}
+%*                                                                     *
+%************************************************************************
 
-lintCoreAtom (CoLitAtom lit)       = returnL (Just (typeOfBasicLit lit))
-lintCoreAtom a@(CoVarAtom v)
-  = checkInScope v     `thenL_`
-    returnL (Just (getIdUniType v))
-\end{code}
+Check a core binding, returning the list of variables bound.
 
 \begin{code}
-lintCoreBinds :: PlainCoreBinding -> LintM [Id]                -- Returns the binders
-lintCoreBinds (CoNonRec binder rhs)
-  = lint_binds_help (binder,rhs)       `thenL_`
-    returnL [binder]
+lintCoreBinding :: CoreBinding -> LintM [Id]
+
+lintCoreBinding (NonRec binder rhs)
+  = lintSingleBinding (binder,rhs) `seqL` returnL [binder]
 
-lintCoreBinds (CoRec pairs) 
+lintCoreBinding (Rec pairs)
   = addInScopeVars binders (
-       mapL lint_binds_help pairs `thenL_`
-       returnL binders
+      mapL lintSingleBinding pairs `seqL` returnL binders
     )
   where
     binders = [b | (b,_) <- pairs]
 
-lint_binds_help (binder,rhs)
+lintSingleBinding (binder,rhs)
   = addLoc (RhsOf binder) (
        -- Check the rhs
-       lintCoreExpr rhs        `thenL` \ maybe_rhs_ty ->
+       lintCoreExpr rhs
 
+       `thenL` \maybe_ty ->
        -- Check match to RHS type
-       (case maybe_rhs_ty of
-         Nothing     -> returnL ()
-         Just rhs_ty -> checkTys (getIdUniType binder) 
-                                  rhs_ty 
-                                  (mkRhsMsg binder rhs_ty)
-       )                       `thenL_` 
-
-       -- Check not isPrimType
-       checkL (not (isPrimType (getIdUniType binder)))
-              (mkRhsPrimMsg binder rhs)
-                               `thenL_`
-
-       -- Check unfolding, if any
-       -- Blegh. This is tricky, because the unfolding is a SimplifiableCoreExpr
-       -- Give up for now
-
-       returnL ()
+       (case maybe_ty of
+         Nothing -> returnL ()
+         Just ty -> checkTys (idType binder) ty (mkRhsMsg binder ty))
+
+       `seqL`
+       -- Check (not isUnpointedType)
+       checkIfSpecDoneL (not (isUnpointedType (idType binder)))
+         (mkRhsPrimMsg binder rhs)  `seqL`
+
+        -- Check whether binder's specialisations contain any out-of-scope variables
+        ifSpecDoneL (mapL (checkSpecIdInScope binder) spec_vars `seqL` returnL ())
+         
+       -- We should check the unfolding, if any, but this is tricky because
+       -- the unfolding is a SimplifiableCoreExpr. Give up for now.
     )
+    where
+     spec_vars = idSpecVars binder
+
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsection[lintCoreExpr]{lintCoreExpr}
+%*                                                                     *
+%************************************************************************
+
 \begin{code}
-lintCoreExpr :: PlainCoreExpr -> LintM (Maybe UniType) -- Nothing if error found
-
-lintCoreExpr (CoVar var)
-  = checkInScope var   `thenL_`
-    returnL (Just ty)
-{-
-    case (splitForalls ty) of { (tyvars, _) ->
-    if null tyvars then
-       returnL (Just ty)
+lintCoreExpr :: CoreExpr -> LintM (Maybe Type) -- Nothing if error found
+
+lintCoreExpr (Var var) 
+  | isAlgCon var = returnL (Just (idType var))
+       -- Micro-hack here... Class decls generate applications of their
+       -- dictionary constructor, but don't generate a binding for the
+       -- constructor (since it would never be used).  After a single round
+       -- of simplification, these dictionary constructors have been
+       -- inlined (from their UnfoldInfo) to CoCons.  Just between
+       -- desugaring and simplfication, though, they appear as naked, unbound
+       -- variables as the function in an application.
+       -- The hack here simply doesn't check for out-of-scope-ness for
+       -- data constructors (at least, in a function position).
+
+  | otherwise    = checkIdInScope var `seqL` returnL (Just (idType var))
+
+lintCoreExpr (Lit lit) = returnL (Just (literalType lit))
+
+lintCoreExpr (Note (Coerce to_ty from_ty) expr)
+  = lintCoreExpr expr  `thenMaybeL` \ expr_ty ->
+    lintTy to_ty       `seqL`
+    lintTy from_ty     `seqL`
+    checkTys from_ty expr_ty (mkCoerceErr from_ty expr_ty)     `seqL`
+    returnL (Just to_ty)
+
+lintCoreExpr (Note other_note expr)
+  = lintCoreExpr expr
+
+lintCoreExpr (Let binds body)
+  = lintCoreBinding binds `thenL` \binders ->
+    if (null binders) then
+       lintCoreExpr body  -- Can't add a new source location
     else
-       addErrL (mkUnappTyMsg var ty)   `thenL_`
-       returnL Nothing
-    }
--}
-  where
-    ty = getIdUniType var
-
-lintCoreExpr (CoLit lit)       = returnL (Just (typeOfBasicLit lit))
-lintCoreExpr (CoSCC label expr)        = lintCoreExpr expr
-
-lintCoreExpr (CoLet binds body)        
-  = lintCoreBinds binds                `thenL` \ binders ->
-    ASSERT(not (null binders))
-    addLoc (BodyOfLetRec binders) (
-    addInScopeVars binders (
-       lintCoreExpr body
-    ))
-
-lintCoreExpr e@(CoCon con tys args)
-  = checkTyApp con_ty tys (mkTyAppMsg e)    `thenMaybeL` \ con_tau_ty ->
-    -- Note: no call to checkSpecTyApp;
-    -- we allow CoCons applied to unboxed types to sail through
-    mapMaybeL lintCoreAtom args                            `thenL` \ maybe_arg_tys ->
-    case maybe_arg_tys of
-      Nothing      -> returnL Nothing
-      Just arg_tys  -> checkFunApp con_tau_ty arg_tys (mkFunAppMsg con_tau_ty arg_tys e)
-  where
-    con_ty = getIdUniType con
-
-lintCoreExpr e@(CoPrim op tys args)
-  = checkTyApp op_ty tys (mkTyAppMsg e)                `thenMaybeL` \ op_tau_ty ->
-    -- checkSpecTyApp e tys (mkSpecTyAppMsg e) `thenMaybeL_`
-    mapMaybeL lintCoreAtom args                        `thenL` \ maybe_arg_tys ->
-    case maybe_arg_tys of
-      Nothing -> returnL Nothing
-      Just arg_tys -> checkFunApp op_tau_ty arg_tys (mkFunAppMsg op_tau_ty arg_tys e)
-  where
-    op_ty = typeOfPrimOp op
+      addLoc (BodyOfLetRec binders)
+       (addInScopeVars binders (lintCoreExpr body))
+
+lintCoreExpr e@(Con con args)
+  = checkL (isDataCon con) (mkConErrMsg e)     `seqL`
+    lintCoreArgs {-False-} e (dataConRepType con) args
+    -- Note: we don't check for primitive types in these arguments
+
+lintCoreExpr e@(Prim op args)
+  = lintCoreArgs {-True-} e (primOpType op) args
+    -- Note: we do check for primitive types in these arguments
+
+lintCoreExpr e@(App fun@(Var v) arg) | isBottomingId v
+  = lintCoreExpr fun `thenMaybeL` \ ty -> lintCoreArg {-False-} e ty arg
+    -- Note: we don't check for primitive types in argument to 'error'
+
+lintCoreExpr e@(App fun arg)
+  = lintCoreExpr fun `thenMaybeL` \ty -> lintCoreArg {-True-} e ty arg
+    -- Note: we do check for primitive types in this argument
+
+lintCoreExpr (Lam (ValBinder var) expr)
+  = addLoc (LambdaBodyOf var)
+      (addInScopeVars [var]
+       (lintCoreExpr expr `thenMaybeL` \ty ->
+        returnL (Just (mkFunTy (idType var) ty))))
+
+lintCoreExpr (Lam (TyBinder tyvar) expr)
+  = lintCoreExpr expr `thenMaybeL` \ty ->
+    returnL (Just(mkForAllTy tyvar ty))
+    -- ToDo: Should add in-scope type variable at this point
+
+lintCoreExpr e@(Case scrut alts)
+ = lintCoreExpr scrut `thenMaybeL` \ty ->
+   lintCoreAlts alts ty
+\end{code}
 
-lintCoreExpr e@(CoApp fun arg)
-  = lce e []
-  where
-    lce (CoApp fun arg) arg_tys = lintCoreAtom arg     `thenMaybeL` \ arg_ty ->
-                                 lce fun (arg_ty:arg_tys)
+%************************************************************************
+%*                                                                     *
+\subsection[lintCoreArgs]{lintCoreArgs}
+%*                                                                     *
+%************************************************************************
+
+The boolean argument indicates whether we should flag type
+applications to primitive types as being errors.
+
+\begin{code}
+lintCoreArgs :: {-Bool ->-} CoreExpr -> Type -> [CoreArg] -> LintM (Maybe Type)
+
+lintCoreArgs _ ty [] = returnL (Just ty)
+lintCoreArgs e ty (a : args)
+  = lintCoreArg  e ty  a `thenMaybeL` \ res ->
+    lintCoreArgs e res args
+\end{code}
+
+%************************************************************************
+%*                                                                     *
+\subsection[lintCoreArg]{lintCoreArg}
+%*                                                                     *
+%************************************************************************
 
-    lce other_fun arg_tys = lintCoreExpr other_fun     `thenMaybeL` \ fun_ty ->
-                           checkFunApp fun_ty arg_tys (mkFunAppMsg fun_ty arg_tys e)
+\begin{code}
+lintCoreArg :: {-Bool ->-} CoreExpr -> Type -> CoreArg -> LintM (Maybe Type)
 
-lintCoreExpr e@(CoTyApp fun ty_arg)
-  = lce e []
+lintCoreArg e ty (LitArg lit)
+  = -- Make sure function type matches argument
+    case (splitFunTy_maybe ty) of
+      Just (arg,res) | (lit_ty == arg) -> returnL(Just res)
+      _ -> addErrL (mkAppMsg ty lit_ty e) `seqL` returnL Nothing
+  where
+    lit_ty = literalType lit
+
+lintCoreArg e ty (VarArg v)
+  = -- Make sure variable is bound
+    checkIdInScope v `seqL`
+    -- Make sure function type matches argument
+    case (splitFunTy_maybe ty) of
+      Just (arg,res) | (var_ty == arg) -> returnL(Just res)
+      _ -> addErrL (mkAppMsg ty var_ty e) `seqL` returnL Nothing
   where
-    lce (CoTyApp fun ty_arg) ty_args = lce fun (ty_arg:ty_args)
-
-    lce other_fun ty_args = lintCoreExpr other_fun     `thenMaybeL` \ fun_ty ->
-                           checkTyApp fun_ty ty_args (mkTyAppMsg e)
-                                                       `thenMaybeL` \ res_ty ->
-                           checkSpecTyApp other_fun ty_args (mkSpecTyAppMsg e)
-                                                       `thenMaybeL_`
-                           returnL (Just res_ty)
-
-lintCoreExpr (CoLam binders expr)
-  = ASSERT (not (null binders))
-    addLoc (LambdaBodyOf binders) (
-    addInScopeVars binders (
-       lintCoreExpr expr   `thenMaybeL` \ body_ty ->
-       returnL (Just (foldr (mkFunTy . getIdUniType) body_ty binders))
-    ))
-
-lintCoreExpr (CoTyLam tyvar expr)
-  = lintCoreExpr expr          `thenMaybeL` \ body_ty ->
-    case quantifyTy [tyvar] body_ty of
-      (_, ty) -> returnL (Just ty) -- not worried about the TyVarTemplates that come back
-
-lintCoreExpr e@(CoCase scrut alts)
- = lintCoreExpr scrut          `thenMaybeL` \ scrut_ty ->
-
-       -- Check that it is a data type
-   case getUniDataTyCon_maybe scrut_ty of
-       Nothing -> addErrL (mkCaseDataConMsg e) `thenL_`
-                  returnL Nothing
-       Just (tycon, _, _)
-               -> lintCoreAlts alts scrut_ty tycon
-
-lintCoreAlts :: PlainCoreCaseAlternatives
-            -> UniType                 -- Type of scrutinee
-            -> TyCon                   -- TyCon pinned on the case
-            -> LintM (Maybe UniType)   -- Type of alternatives
-
-lintCoreAlts alts scrut_ty case_tycon
-  = (case alts of
-        CoAlgAlts alg_alts deflt ->  
-          chk_prim_type False case_tycon       `thenL_`
-          chk_non_abstract_type case_tycon     `thenL_`
-          mapL (lintAlgAlt scrut_ty) alg_alts  `thenL` \ maybe_alt_tys ->
-          lintDeflt deflt scrut_ty             `thenL` \ maybe_deflt_ty ->
-          returnL (maybe_deflt_ty : maybe_alt_tys)
-
-        CoPrimAlts prim_alts deflt -> 
-          chk_prim_type True case_tycon         `thenL_`
-          mapL (lintPrimAlt scrut_ty) prim_alts `thenL` \ maybe_alt_tys ->
-          lintDeflt deflt scrut_ty              `thenL` \ maybe_deflt_ty ->
-          returnL (maybe_deflt_ty : maybe_alt_tys)
-    )                                           `thenL` \ maybe_result_tys ->
-        -- Check the result types
-    case catMaybes (maybe_result_tys) of
+    var_ty = idType v
+
+lintCoreArg e ty a@(TyArg arg_ty)
+  = lintTy arg_ty                      `seqL`
+
+    case (splitForAllTy_maybe ty) of
+      Nothing -> addErrL (mkTyAppMsg SLIT("Illegal") ty arg_ty e) `seqL` returnL Nothing
+
+      Just (tyvar,body) ->
+       let
+           tyvar_kind = tyVarKind tyvar
+           argty_kind = typeKind arg_ty
+       in
+       if argty_kind `hasMoreBoxityInfo` tyvar_kind
+               -- Arg type might be boxed for a function with an uncommitted
+               -- tyvar; notably this is used so that we can give
+               --      error :: forall a:*. String -> a
+               -- and then apply it to both boxed and unboxed types.
+        then
+           returnL(Just(instantiateTy (mkTyVarEnv [(tyvar,arg_ty)]) body))
+       else
+           pprTrace "lintCoreArg:kinds:" (hsep [ppr tyvar_kind, ppr argty_kind]) $
+           addErrL (mkKindErrMsg tyvar arg_ty e) `seqL` returnL Nothing
+\end{code}
+
+%************************************************************************
+%*                                                                     *
+\subsection[lintCoreAlts]{lintCoreAlts}
+%*                                                                     *
+%************************************************************************
+
+\begin{code}
+lintCoreAlts :: CoreCaseAlts
+            -> Type                    -- Type of scrutinee
+--          -> TyCon                   -- TyCon pinned on the case
+            -> LintM (Maybe Type)      -- Type of alternatives
+
+lintCoreAlts whole_alts@(AlgAlts alts deflt) ty --tycon
+  = -- Check tycon is not a primitive tycon
+--    addErrIfL (isPrimTyCon tycon) (mkCasePrimMsg tycon)
+--    `seqL`
+    -- Check we are scrutinising a proper datatype
+    -- (ToDo: robustify)
+--    addErrIfL (not (tyConFamilySize tycon >= 1)) (mkCaseAbstractMsg tycon)
+--    `seqL`
+    lintDeflt deflt ty
+    `thenL` \maybe_deflt_ty ->
+    mapL (lintAlgAlt ty {-tycon-}) alts
+    `thenL` \maybe_alt_tys ->
+    -- Check the result types
+    case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
       []            -> returnL Nothing
 
-      (first_ty:tys) -> mapL check tys `thenL_`
+      (first_ty:tys) -> mapL check tys `seqL`
                        returnL (Just first_ty)
        where
-         check ty = checkTys first_ty ty (mkCaseAltMsg alts)
-  where
-    chk_prim_type prim_required tycon
-      = if (isPrimTyCon tycon == prim_required) then
-           returnL ()
-       else
-           addErrL (mkCasePrimMsg prim_required tycon)
-
-    chk_non_abstract_type tycon
-      = case (getTyConFamilySize tycon) of
-         Nothing -> addErrL (mkCaseAbstractMsg tycon)
-         Just  _ -> returnL ()
+         check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
+
+lintCoreAlts whole_alts@(PrimAlts alts deflt) ty --tycon
+  = -- Check tycon is a primitive tycon
+--    addErrIfL (not (isPrimTyCon tycon)) (mkCaseNotPrimMsg tycon)
+--    `seqL`
+    mapL (lintPrimAlt ty) alts
+    `thenL` \maybe_alt_tys ->
+    lintDeflt deflt ty
+    `thenL` \maybe_deflt_ty ->
+    -- Check the result types
+    case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
+      []            -> returnL Nothing
 
+      (first_ty:tys) -> mapL check tys `seqL`
+                       returnL (Just first_ty)
+       where
+         check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
 
 lintAlgAlt scrut_ty (con,args,rhs)
-  = (case getUniDataTyCon_maybe scrut_ty of
-      Nothing -> 
-        addErrL (mkAlgAltMsg1 scrut_ty)
-      Just (tycon, tys_applied, cons) ->
+  = (case splitAlgTyConApp_maybe scrut_ty of
+      Just (tycon, tys_applied, cons) | isDataTyCon tycon ->
         let
-          (_, arg_tys, _) = getInstantiatedDataConSig con tys_applied
+          arg_tys = dataConArgTys con tys_applied
         in
-        checkL (con `elem` cons) (mkAlgAltMsg2 scrut_ty con) `thenL_`
-        checkL (length arg_tys == length args) (mkAlgAltMsg3 con args) 
-                                                                `thenL_`
-        mapL check (arg_tys `zipEqual` args)                    `thenL_`
+        checkL (con `elem` cons) (mkAlgAltMsg2 scrut_ty con) `seqL`
+        checkL (length arg_tys == length args) (mkAlgAltMsg3 con args)
+                                                                `seqL`
+        mapL check (zipEqual "lintAlgAlt" arg_tys args)         `seqL`
         returnL ()
-    )                                                           `thenL_`
+
+      other -> addErrL (mkAlgAltMsg1 scrut_ty)
+    )                                                           `seqL`
     addInScopeVars args        (
         lintCoreExpr rhs
     )
   where
-    check (ty, arg) = checkTys ty (getIdUniType arg) (mkAlgAltMsg4 ty arg)
+    check (ty, arg) = checkTys ty (idType arg) (mkAlgAltMsg4 ty arg)
 
     -- elem: yes, the elem-list here can sometimes be long-ish,
     -- but as it's use-once, probably not worth doing anything different
@@ -308,19 +408,29 @@ lintAlgAlt scrut_ty (con,args,rhs)
     elem _ []      = False
     elem x (y:ys)   = x==y || elem x ys
 
-lintPrimAlt scrut_ty alt@(lit,rhs)
- = checkTys (typeOfBasicLit lit) scrut_ty (mkPrimAltMsg alt)   `thenL_`
+lintPrimAlt ty alt@(lit,rhs)
+ = checkTys (literalType lit) ty (mkPrimAltMsg alt) `seqL`
    lintCoreExpr rhs
-   
-lintDeflt CoNoDefault scrut_ty = returnL Nothing
-lintDeflt deflt@(CoBindDefault binder rhs) scrut_ty 
-  = checkTys (getIdUniType binder) scrut_ty (mkDefltMsg deflt) `thenL_`
-    addInScopeVars [binder] (
-       lintCoreExpr rhs
-    )
+
+lintDeflt NoDefault _ = returnL Nothing
+lintDeflt deflt@(BindDefault binder rhs) ty
+  = checkTys (idType binder) ty (mkDefltMsg deflt) `seqL`
+    addInScopeVars [binder] (lintCoreExpr rhs)
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsection[lint-types]{Types}
+%*                                                                     *
+%************************************************************************
+
+\begin{code}
+lintTy :: Type -> LintM ()
+lintTy ty = returnL ()
+-- ToDo: Check that ty is well-kinded and has no unbound tyvars
+\end{code}
 
+    
 %************************************************************************
 %*                                                                     *
 \subsection[lint-monad]{The Lint monad}
@@ -330,51 +440,48 @@ lintDeflt deflt@(CoBindDefault binder rhs) scrut_ty
 \begin{code}
 type LintM a = Bool            -- True <=> specialisation has been done
            -> [LintLocInfo]    -- Locations
-           -> UniqSet Id       -- Local vars in scope
+           -> IdSet            -- Local vars in scope
            -> Bag ErrMsg       -- Error messages so far
            -> (a, Bag ErrMsg)  -- Result and error messages (if any)
 
-type ErrMsg = PprStyle -> Pretty
-
 data LintLocInfo
   = RhsOf Id           -- The variable bound
-  | LambdaBodyOf [Id]  -- The lambda-binder
+  | LambdaBodyOf Id    -- The lambda-binder
   | BodyOfLetRec [Id]  -- One of the binders
   | ImportedUnfolding SrcLoc -- Some imported unfolding (ToDo: say which)
 
 instance Outputable LintLocInfo where
-    ppr sty (RhsOf v)
-      = ppBesides [ppr sty (getSrcLoc v), ppStr ": [RHS of ", pp_binders sty [v], ppStr "]"]
+    ppr (RhsOf v)
+      = ppr (getSrcLoc v) <> colon <+> 
+       brackets (ptext SLIT("RHS of") <+> pp_binders [v])
 
-    ppr sty (LambdaBodyOf bs)
-      = ppBesides [ppr sty (getSrcLoc (head bs)),
-               ppStr ": [in body of lambda with binders ", pp_binders sty bs, ppStr "]"]
+    ppr (LambdaBodyOf b)
+      = ppr (getSrcLoc b) <> colon <+>
+       brackets (ptext SLIT("in body of lambda with binder") <+> pp_binder b)
 
-    ppr sty (BodyOfLetRec bs)
-      = ppBesides [ppr sty (getSrcLoc (head bs)),
-               ppStr ": [in body of letrec with binders ", pp_binders sty bs, ppStr "]"]
+    ppr (BodyOfLetRec bs)
+      = ppr (getSrcLoc (head bs)) <> colon <+>
+       brackets (ptext SLIT("in body of letrec with binders") <+> pp_binders bs)
 
-    ppr sty (ImportedUnfolding locn)
-      = ppBeside (ppr sty locn) (ppStr ": [in an imported unfolding]")
+    ppr (ImportedUnfolding locn)
+      = ppr locn <> colon <+>
+       brackets (ptext SLIT("in an imported unfolding"))
 
-pp_binders :: PprStyle -> [Id] -> Pretty
-pp_binders sty bs
-  = ppInterleave ppComma (map pp_binder bs)
-  where
-    pp_binder b
-      = ppCat [ppr sty b, ppStr "::", ppr sty (getIdUniType b)]
+pp_binders :: [Id] -> SDoc
+pp_binders bs = sep (punctuate comma (map pp_binder bs))
+
+pp_binder :: Id -> SDoc
+pp_binder b = hsep [ppr b, text "::", ppr (idType b)]
 \end{code}
 
 \begin{code}
 initL :: LintM a -> Bool -> Maybe ErrMsg
 initL m spec_done
-  = case (m spec_done [] emptyUniqSet emptyBag) of { (_, errs) ->
+  = case (m spec_done [] emptyIdSet emptyBag) of { (_, errs) ->
     if isEmptyBag errs then
        Nothing
     else
-       Just ( \ sty ->
-         ppAboves [ msg sty | msg <- bagToList errs ]
-       )
+       Just (vcat (bagToList errs))
     }
 
 returnL :: a -> LintM a
@@ -382,12 +489,12 @@ returnL r spec loc scope errs = (r, errs)
 
 thenL :: LintM a -> (a -> LintM b) -> LintM b
 thenL m k spec loc scope errs
-  = case m spec loc scope errs of 
+  = case m spec loc scope errs of
       (r, errs') -> k r spec loc scope errs'
 
-thenL_ :: LintM a -> LintM b -> LintM b
-thenL_ m k spec loc scope errs
-  = case m spec loc scope errs of 
+seqL :: LintM a -> LintM b -> LintM b
+seqL m k spec loc scope errs
+  = case m spec loc scope errs of
       (_, errs') -> k spec loc scope errs'
 
 thenMaybeL :: LintM (Maybe a) -> (a -> LintM (Maybe b)) -> LintM (Maybe b)
@@ -396,12 +503,6 @@ thenMaybeL m k spec loc scope errs
       (Nothing, errs2) -> (Nothing, errs2)
       (Just r,  errs2) -> k r spec loc scope errs2
 
-thenMaybeL_ :: LintM (Maybe a) -> LintM (Maybe b) -> LintM (Maybe b)
-thenMaybeL_ m k spec loc scope errs
-  = case m spec loc scope errs of
-      (Nothing, errs2) -> (Nothing, errs2)
-      (Just _,  errs2) -> k spec loc scope errs2
-
 mapL :: (a -> LintM b) -> [a] -> LintM [b]
 mapL f [] = returnL []
 mapL f (x:xs)
@@ -423,6 +524,15 @@ checkL :: Bool -> ErrMsg -> LintM ()
 checkL True  msg spec loc scope errs = ((), errs)
 checkL False msg spec loc scope errs = ((), addErr errs msg loc)
 
+checkIfSpecDoneL :: Bool -> ErrMsg -> LintM ()
+checkIfSpecDoneL True  msg spec  loc scope errs = ((), errs)
+checkIfSpecDoneL False msg True  loc scope errs = ((), addErr errs msg loc)
+checkIfSpecDoneL False msg False loc scope errs = ((), errs)
+
+ifSpecDoneL :: LintM () -> LintM ()
+ifSpecDoneL m False loc scope errs = ((), errs)
+ifSpecDoneL m True  loc scope errs = m True loc scope errs
+
 addErrL :: ErrMsg -> LintM ()
 addErrL msg spec loc scope errs = ((), addErr errs msg loc)
 
@@ -430,9 +540,7 @@ addErr :: Bag ErrMsg -> ErrMsg -> [LintLocInfo] -> Bag ErrMsg
 
 addErr errs_so_far msg locs
   = ASSERT (not (null locs))
-    errs_so_far `snocBag` ( \ sty ->
-    ppHang (ppr sty (head locs)) 4 (msg sty)
-    )
+    errs_so_far `snocBag` (hang (ppr (head locs)) 4 msg)
 
 addLoc :: LintLocInfo -> LintM a -> LintM a
 addLoc extra_loc m spec loc scope errs
@@ -445,207 +553,145 @@ addInScopeVars ids m spec loc scope errs
     -- For now, it's just a "trace"; we may make
     -- a real error out of it...
     let
-       new_set = mkUniqSet ids
+       new_set = mkIdSet ids
 
-       shadowed = scope `intersectUniqSets` new_set
+--     shadowed = scope `intersectIdSets` new_set
     in
 --  After adding -fliberate-case, Simon decided he likes shadowed
 --  names after all.  WDP 94/07
 --  (if isEmptyUniqSet shadowed
 --  then id
---  else pprTrace "Shadowed vars:" (ppr PprDebug (uniqSetToList shadowed))) (
-    m spec loc (scope `unionUniqSets` new_set) errs
+--  else pprTrace "Shadowed vars:" (ppr (uniqSetToList shadowed))) (
+    m spec loc (scope `unionIdSets` new_set) errs
 --  )
 \end{code}
 
 \begin{code}
-checkTyApp :: UniType
-          -> [UniType]
-          -> ErrMsg
-          -> LintM (Maybe UniType)
-
-checkTyApp forall_ty ty_args msg spec_done loc scope errs
-  = if (not spec_done && n_ty_args /= n_tyvars)
-    || (spec_done     && n_ty_args  > n_tyvars)
-    --
-    -- Things are *not* OK if:
-    --
-    -- * Unsaturated type app before specialisation has been done;
-    --
-    -- * Oversaturated type app after specialisation (eta reduction
-    --   may well be happening...);
-    --
-    -- Note: checkTyApp is usually followed by a call to checkSpecTyApp.
-    --
-    then (Nothing,     addErr errs msg loc)
-    else (Just res_ty, errs)
-  where
-    (tyvars, rho_ty) = splitForalls forall_ty
-    n_tyvars = length tyvars
-    n_ty_args = length ty_args
-    leftover_tyvars = drop n_ty_args tyvars
-    inst_env = tyvars `zip` ty_args
-    res_ty = mkForallTy leftover_tyvars (instantiateTy inst_env rho_ty)
-\end{code}
-
-\begin{code}
-checkSpecTyApp :: PlainCoreExpr -> [UniType] -> ErrMsg -> LintM (Maybe ())
-
-checkSpecTyApp expr ty_args msg spec_done loc scope errs
-  = if spec_done
-    && any isUnboxedDataType ty_args
-    && not (an_application_of_error expr)
-    then (Nothing, addErr errs msg loc)
-    else (Just (), errs)
-  where
-     -- always safe (but maybe unfriendly) to say "False"
-    an_application_of_error (CoVar id) | isBottomingId id = True
-    an_application_of_error _ = False
-\end{code}
-
-\begin{code}
-checkFunApp :: UniType                 -- The function type
-           -> [UniType]        -- The arg type(s)
-           -> ErrMsg           -- Error messgae
-           -> LintM (Maybe UniType)    -- The result type
-
-checkFunApp fun_ty arg_tys msg spec loc scope errs
-  = cfa res_ty expected_arg_tys arg_tys
-  where
-    (expected_arg_tys, res_ty) = splitTyArgs fun_ty
-
-    cfa res_ty expected []     -- Args have run out; that's fine
-       = (Just (glueTyArgs expected res_ty), errs)
-
-    cfa res_ty [] arg_tys      -- Expected arg tys ran out first; maybe res_ty is a 
-                               -- dictionary type which is actually a function?
-       = case splitTyArgs (unDictifyTy res_ty) of
-           ([], _)                 -> (Nothing, addErr errs msg loc)   -- Too many args
-           (new_expected, new_res) -> cfa new_res new_expected arg_tys
-
-    cfa res_ty (expected_arg_ty:expected_arg_tys) (arg_ty:arg_tys)
-       = case (cmpUniType True{-properly-} expected_arg_ty arg_ty) of
-               EQ_ -> cfa res_ty expected_arg_tys arg_tys
-               other -> (Nothing, addErr errs msg loc)                 -- Arg mis-match
-\end{code}
-
-\begin{code}
-checkInScope :: Id -> LintM ()
-checkInScope id spec loc scope errs
-  = if isLocallyDefined id && not (id `elementOfUniqSet` scope) then
-       ((), addErr errs (\ sty -> ppCat [ppr sty id, ppStr "is out of scope"]) loc)
+checkIdInScope :: Id -> LintM ()
+checkIdInScope id 
+  = checkInScope (ptext SLIT("is out of scope")) id
+
+checkSpecIdInScope :: Id -> Id -> LintM ()
+checkSpecIdInScope binder id 
+  = checkInScope msg id
+    where
+     msg = ptext SLIT("is out of scope inside specialisation info for") <+> 
+          ppr binder
+
+checkInScope :: SDoc -> Id -> LintM ()
+checkInScope loc_msg id spec loc scope errs
+  = let
+       id_name = getName id
+    in
+    if isLocallyDefined id_name && not (id `elementOfIdSet` scope) then
+      ((), addErr errs (hsep [ppr id, loc_msg]) loc)
     else
-       ((), errs)
+      ((),errs)
 
-checkTys :: UniType -> UniType -> ErrMsg -> LintM ()
+checkTys :: Type -> Type -> ErrMsg -> LintM ()
 checkTys ty1 ty2 msg spec loc scope errs
-  = case (cmpUniType True{-properly-} ty1 ty2) of
-       EQ_   -> ((), errs)
-       other -> ((), addErr errs msg loc)
+  = if ty1 == ty2 then ((), errs) else ((), addErr errs msg loc)
 \end{code}
 
 \begin{code}
-mkCaseAltMsg :: PlainCoreCaseAlternatives -> ErrMsg
-mkCaseAltMsg alts sty
-  = ppAbove (ppStr "In some case alternatives, type of alternatives not all same:")
-           (ppr sty alts)
-
-mkCaseDataConMsg :: PlainCoreExpr -> ErrMsg
-mkCaseDataConMsg expr sty
-  = ppAbove (ppStr "A case scrutinee not a type-constructor type:")
-           (pp_expr sty expr)
-
-mkCasePrimMsg :: Bool -> TyCon -> ErrMsg
-mkCasePrimMsg True tycon sty
-  = ppAbove (ppStr "A primitive case on a non-primitive type:")
-           (ppr sty tycon)
-mkCasePrimMsg False tycon sty
-  = ppAbove (ppStr "An algebraic case on a primitive type:")
-           (ppr sty tycon)
+mkConErrMsg e
+  = ($$) (ptext SLIT("Application of newtype constructor:"))
+           (ppr e)
+
+
+mkCaseAltMsg :: CoreCaseAlts -> ErrMsg
+mkCaseAltMsg alts
+  = ($$) (ptext SLIT("Type of case alternatives not the same:"))
+           (ppr alts)
 
 mkCaseAbstractMsg :: TyCon -> ErrMsg
-mkCaseAbstractMsg tycon sty
-  = ppAbove (ppStr "An algebraic case on an abstract type:")
-           (ppr sty tycon)
-
-mkDefltMsg :: PlainCoreCaseDefault -> ErrMsg
-mkDefltMsg deflt sty
-  = ppAbove (ppStr "Binder in default case of a case expression doesn't match type of scrutinee:")
-           (ppr sty deflt)
-
-mkFunAppMsg :: UniType -> [UniType] -> PlainCoreExpr -> ErrMsg
-mkFunAppMsg fun_ty arg_tys expr sty
-  = ppAboves [ppStr "In a function application, function type doesn't match arg types:",
-             ppHang (ppStr "Function type:") 4 (ppr sty fun_ty),
-             ppHang (ppStr "Arg types:") 4 (ppAboves (map (ppr sty) arg_tys)),
-             ppHang (ppStr "Expression:") 4 (pp_expr sty expr)]
-
-mkUnappTyMsg :: Id -> UniType -> ErrMsg
-mkUnappTyMsg var ty sty
-  = ppAboves [ppStr "Variable has a for-all type, but isn't applied to any types.",
-             ppBeside (ppStr "Var:      ") (ppr sty var),
-             ppBeside (ppStr "Its type: ") (ppr sty ty)]
-
-mkAlgAltMsg1 :: UniType -> ErrMsg
-mkAlgAltMsg1 ty sty
-  = ppAbove (ppStr "In some case statement, type of scrutinee is not a data type:")
-           (ppr sty ty)
-
-mkAlgAltMsg2 :: UniType -> Id -> ErrMsg
-mkAlgAltMsg2 ty con sty
-  = ppAboves [
-       ppStr "In some algebraic case alternative, constructor is not a constructor of scrutinee type:",
-       ppr sty ty,
-       ppr sty con
+mkCaseAbstractMsg tycon
+  = ($$) (ptext SLIT("An algebraic case on some weird type:"))
+           (ppr tycon)
+
+mkDefltMsg :: CoreCaseDefault -> ErrMsg
+mkDefltMsg deflt
+  = ($$) (ptext SLIT("Binder in case default doesn't match type of scrutinee:"))
+           (ppr deflt)
+
+mkAppMsg :: Type -> Type -> CoreExpr -> ErrMsg
+mkAppMsg fun arg expr
+  = vcat [ptext SLIT("Argument value doesn't match argument type:"),
+             hang (ptext SLIT("Fun type:")) 4 (ppr fun),
+             hang (ptext SLIT("Arg type:")) 4 (ppr arg),
+             hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
+
+mkKindErrMsg :: TyVar -> Type -> CoreExpr -> ErrMsg
+mkKindErrMsg tyvar arg_ty expr
+  = vcat [ptext SLIT("Kinds don't match in type application:"),
+         hang (ptext SLIT("Type variable:"))
+                4 (ppr tyvar <+> ptext SLIT("::") <+> ppr (tyVarKind tyvar)),
+         hang (ptext SLIT("Arg type:"))   
+                4 (ppr arg_ty <+> ptext SLIT("::") <+> ppr (typeKind arg_ty)),
+         hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
+
+mkTyAppMsg :: FAST_STRING -> Type -> Type -> CoreExpr -> ErrMsg
+mkTyAppMsg msg ty arg expr
+  = vcat [hsep [ptext msg, ptext SLIT("type application:")],
+             hang (ptext SLIT("Exp type:"))
+                4 (ppr ty <+> ptext SLIT("::") <+> ppr (typeKind ty)),
+             hang (ptext SLIT("Arg type:"))   
+                4 (ppr arg <+> ptext SLIT("::") <+> ppr (typeKind arg)),
+             hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
+
+mkAlgAltMsg1 :: Type -> ErrMsg
+mkAlgAltMsg1 ty
+  = ($$) (text "In some case statement, type of scrutinee is not a data type:")
+           (ppr ty)
+
+mkAlgAltMsg2 :: Type -> Id -> ErrMsg
+mkAlgAltMsg2 ty con
+  = vcat [
+       text "In some algebraic case alternative, constructor is not a constructor of scrutinee type:",
+       ppr ty,
+       ppr con
     ]
 
 mkAlgAltMsg3 :: Id -> [Id] -> ErrMsg
-mkAlgAltMsg3 con alts sty
-  = ppAboves [
-       ppStr "In some algebraic case alternative, number of arguments doesn't match constructor:",
-       ppr sty con,
-       ppr sty alts
+mkAlgAltMsg3 con alts
+  = vcat [
+       text "In some algebraic case alternative, number of arguments doesn't match constructor:",
+       ppr con,
+       ppr alts
     ]
 
-mkAlgAltMsg4 :: UniType -> Id -> ErrMsg
-mkAlgAltMsg4 ty arg sty
-  = ppAboves [
-       ppStr "In some algebraic case alternative, type of argument doesn't match data constructor:",
-       ppr sty ty,
-       ppr sty arg
+mkAlgAltMsg4 :: Type -> Id -> ErrMsg
+mkAlgAltMsg4 ty arg
+  = vcat [
+       text "In some algebraic case alternative, type of argument doesn't match data constructor:",
+       ppr ty,
+       ppr arg
     ]
 
-mkPrimAltMsg :: (BasicLit, PlainCoreExpr) -> ErrMsg
-mkPrimAltMsg alt sty
-  = ppAbove (ppStr "In a primitive case alternative, type of literal doesn't match type of scrutinee:")
-           (ppr sty alt)
-
-mkRhsMsg :: Id -> UniType -> ErrMsg
-mkRhsMsg binder ty sty
-  = ppAboves [ppCat [ppStr "The type of this binder doesn't match the type of its RHS:", 
-                    ppr sty binder],
-             ppCat [ppStr "Binder's type:", ppr sty (getIdUniType binder)],
-             ppCat [ppStr "Rhs type:", ppr sty ty]
+mkPrimAltMsg :: (Literal, CoreExpr) -> ErrMsg
+mkPrimAltMsg alt
+  = ($$)
+    (text "In a primitive case alternative, type of literal doesn't match type of scrutinee:")
+           (ppr alt)
+
+mkRhsMsg :: Id -> Type -> ErrMsg
+mkRhsMsg binder ty
+  = vcat
+    [hsep [ptext SLIT("The type of this binder doesn't match the type of its RHS:"),
+           ppr binder],
+     hsep [ptext SLIT("Binder's type:"), ppr (idType binder)],
+     hsep [ptext SLIT("Rhs type:"), ppr ty]]
+
+mkRhsPrimMsg :: Id -> CoreExpr -> ErrMsg
+mkRhsPrimMsg binder rhs
+  = vcat [hsep [ptext SLIT("The type of this binder is primitive:"),
+                    ppr binder],
+             hsep [ptext SLIT("Binder's type:"), ppr (idType binder)]
             ]
 
-mkRhsPrimMsg :: Id -> PlainCoreExpr -> ErrMsg
-mkRhsPrimMsg binder rhs sty
-  = ppAboves [ppCat [ppStr "The type of this binder is primitive:", 
-                    ppr sty binder],
-             ppCat [ppStr "Binder's type:", ppr sty (getIdUniType binder)]
-            ]
-
-mkTyAppMsg :: PlainCoreExpr -> ErrMsg
-mkTyAppMsg expr sty
-  = ppAboves [ppStr "In a type application, either the function's type doesn't match",
-             ppStr "the argument types, or an argument type is primitive:",
-             pp_expr sty expr]
-
-mkSpecTyAppMsg :: PlainCoreExpr -> ErrMsg
-mkSpecTyAppMsg expr sty
-  = ppAbove (ppStr "Unboxed types in a type application (after specialisation):")
-           (pp_expr sty expr)
-
-pp_expr sty expr
-  = pprCoreExpr sty pprBigCoreBinder pprTypedCoreBinder pprTypedCoreBinder expr
+mkCoerceErr from_ty expr_ty
+  = vcat [ptext SLIT("From-type of Coerce differs from type of enclosed expression"),
+         ptext SLIT("From-type:") <+> ppr from_ty,
+         ptext SLIT("Type of enclosed expr:") <+> ppr expr_ty
+    ]
 \end{code}