[project @ 1998-08-14 11:47:29 by sof]
[ghc-hetmet.git] / ghc / compiler / rename / RnSource.lhs
index 7affaf0..89e484d 100644 (file)
@@ -4,61 +4,47 @@
 \section[RnSource]{Main pass of renamer}
 
 \begin{code}
-#include "HsVersions.h"
-
 module RnSource ( rnDecl, rnHsType, rnHsSigType ) where
 
-IMPORT_1_3(List(partition))
-IMP_Ubiq()
-
-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
-IMPORT_DELOOPER(RnLoop)                -- *check* the RnPass/RnExpr/RnBinds loop-breaking
-#else
-import {-# SOURCE #-} RnExpr
-#endif
+#include "HsVersions.h"
 
+import RnExpr
 import HsSyn
-import HsDecls         ( HsIdInfo(..) )
+import HsDecls         ( HsIdInfo(..), HsStrictnessInfo(..) )
 import HsPragmas
-import HsTypes         ( getTyVarName )
+import HsTypes         ( getTyVarName, pprClassAssertion, cmpHsTypes )
 import RdrHsSyn
 import RnHsSyn
 import HsCore
 import CmdLineOpts     ( opt_IgnoreIfacePragmas )
 
-import RnBinds         ( rnTopBinds, rnMethodBinds )
+import RnBinds         ( rnTopBinds, rnMethodBinds, renameSigs )
 import RnEnv           ( bindTyVarsRn, lookupBndrRn, lookupOccRn, lookupImplicitOccRn, bindLocalsRn,
-                         newSysName, newDfunName, checkDupOrQualNames, checkDupNames,
-                         listType_RDR, tupleType_RDR )
+                         newDfunName, checkDupOrQualNames, checkDupNames, lookupGlobalOccRn,
+                         newLocallyDefinedGlobalName, newImportedGlobalName, ifaceFlavour,
+                         listType_RDR, tupleType_RDR, addImplicitOccRn
+                       )
 import RnMonad
 
-import Name            ( Name, isLocallyDefined, 
-                         OccName(..), occNameString, prefixOccName,
-                         ExportFlag(..),
-                         Provenance,
-                         SYN_IE(NameSet), unionNameSets, emptyNameSet, mkNameSet, unitNameSet,
-                         elemNameSet
+import Name            ( Name, OccName(..), occNameString, prefixOccName,
+                         ExportFlag(..), Provenance(..), NameSet, mkNameSet,
+                         elemNameSet, nameOccName, NamedThing(..)
                        )
-import ErrUtils                ( addErrLoc, addShortErrLocLine, addShortWarnLocLine )
-import FiniteMap       ( emptyFM, lookupFM, addListToFM_C )
+import BasicTypes      ( TopLevelFlag(..) )
+import FiniteMap       ( lookupFM )
 import Id              ( GenId{-instance NamedThing-} )
-import IdInfo          ( IdInfo, StrictnessInfo(..), FBTypeInfo, DemandInfo, ArgUsageInfo )
-import SpecEnv         ( SpecEnv )
+import IdInfo          ( FBTypeInfo, ArgUsageInfo )
 import Lex             ( isLexCon )
-import CoreUnfold      ( Unfolding(..), SimpleUnfolding )
-import MagicUFs                ( MagicUnfoldingFun )
 import PrelInfo                ( derivingOccurrences, evalClass_RDR, numClass_RDR, allClass_NAME )
-import ListSetOps      ( unionLists, minusList )
-import Maybes          ( maybeToBool, catMaybes )
-import Bag             ( emptyBag, unitBag, consBag, unionManyBags, unionBags, listToBag, bagToList )
-import Outputable      ( PprStyle(..), Outputable(..){-instances-} )
-import Pretty
+import Maybes          ( maybeToBool )
+import Bag             ( bagToList )
+import Outputable
 import SrcLoc          ( SrcLoc )
 import Unique          ( Unique )
-import UniqSet         ( SYN_IE(UniqSet) )
+import UniqSet         ( UniqSet )
 import UniqFM          ( UniqFM, lookupUFM )
-import Util    {-      ( isIn, isn'tIn, thenCmp, removeDups, cmpPString,
-                         panic, assertPanic{- , pprTrace ToDo:rm-} ) -}
+import Util
+import List            ( partition, nub )
 \end{code}
 
 rnDecl `renames' declarations.
@@ -92,8 +78,10 @@ rnDecl (SigD (IfaceSig name ty id_infos loc))
   = pushSrcLocRn loc $
     lookupBndrRn name          `thenRn` \ name' ->
     rnHsType ty                        `thenRn` \ ty' ->
+
        -- Get the pragma info (if any).
-    setModeRn (InterfaceMode Optional) $
+    getModeRn                  `thenRn` \ (InterfaceMode _ print_unqual) ->
+    setModeRn (InterfaceMode Optional print_unqual) $
        -- In all the rest of the signature we read in optional mode,
        -- so that (a) we don't die
     mapRn rnIdInfo id_infos    `thenRn` \ id_infos' -> 
@@ -130,7 +118,7 @@ rnDecl (TyD (TyData new_or_data context tycon tyvars condecls derivings pragmas
     ASSERT(isNoDataPragmas pragmas)
     returnRn (TyD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc))
   where
-    data_doc sty = text "the data type declaration for" <+> ppr sty tycon
+    data_doc = text "the data type declaration for" <+> ppr tycon
     con_names = map conDeclName condecls
 
 rnDecl (TyD (TySynonym name tyvars ty src_loc))
@@ -140,7 +128,7 @@ rnDecl (TyD (TySynonym name tyvars ty src_loc))
     rnHsType ty                                        `thenRn` \ ty' ->
     returnRn (TyD (TySynonym name' tyvars' ty' src_loc))
   where
-    syn_doc sty = text "the declaration for type synonym" <+> ppr sty name
+    syn_doc = text "the declaration for type synonym" <+> ppr name
 \end{code}
 
 %*********************************************************
@@ -154,20 +142,27 @@ class declaration in which local names have been replaced by their
 original names, reporting any unknown names.
 
 \begin{code}
-rnDecl (ClD (ClassDecl context cname tyvar sigs mbinds pragmas src_loc))
+rnDecl (ClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname src_loc))
   = pushSrcLocRn src_loc $
-    bindTyVarsRn cls_doc [tyvar]                       ( \ [tyvar'] ->
+
+    lookupBndrRn cname                                 `thenRn` \ cname' ->
+    lookupBndrRn tname                                 `thenRn` \ tname' ->
+    lookupBndrRn dname                                 `thenRn` \ dname' ->
+
+    bindTyVarsRn cls_doc tyvars                                        ( \ tyvars' ->
        rnContext context                                       `thenRn` \ context' ->
-       lookupBndrRn cname                                      `thenRn` \ cname' ->
 
             -- Check the signatures
-       checkDupOrQualNames sig_doc sig_names           `thenRn_` 
-       mapRn (rn_op cname' (getTyVarName tyvar')) sigs `thenRn` \ sigs' ->
-       returnRn (tyvar', context', cname', sigs')
-    )                                                  `thenRn` \ (tyvar', context', cname', sigs') ->
+       let
+         clas_tyvar_names = map getTyVarName tyvars'
+       in
+       checkDupOrQualNames sig_doc sig_rdr_names_w_locs        `thenRn_` 
+       mapRn (rn_op cname' clas_tyvar_names) sigs              `thenRn` \ sigs' ->
+       returnRn (tyvars', context', sigs')
+    )                                                  `thenRn` \ (tyvars', context', sigs') ->
 
        -- Check the methods
-    checkDupOrQualNames meth_doc meth_names            `thenRn_`
+    checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
     rnMethodBinds mbinds                               `thenRn` \ mbinds' ->
 
        -- Typechecker is responsible for checking that we only
@@ -176,49 +171,57 @@ rnDecl (ClD (ClassDecl context cname tyvar sigs mbinds pragmas src_loc))
        -- for instance decls.
 
     ASSERT(isNoClassPragmas pragmas)
-    returnRn (ClD (ClassDecl context' cname' tyvar' sigs' mbinds' NoClassPragmas src_loc))
+    returnRn (ClD (ClassDecl context' cname' tyvars' sigs' mbinds' NoClassPragmas tname' dname' src_loc))
   where
-    cls_doc sty  = text "the declaration for class"    <+> ppr sty cname
-    sig_doc sty  = text "the signatures for class"     <+> ppr sty cname
-    meth_doc sty = text "the default-methods for class" <+> ppr sty cname
+    cls_doc  = text "the declaration for class"        <+> ppr cname
+    sig_doc  = text "the signatures for class"         <+> ppr cname
+    meth_doc = text "the default-methods for class"    <+> ppr cname
 
-    sig_names   = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
-    meth_names   = bagToList (collectMonoBinders mbinds)
+    sig_rdr_names_w_locs  = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
+    meth_rdr_names_w_locs = bagToList (collectMonoBinders mbinds)
+    meth_rdr_names       = map fst meth_rdr_names_w_locs
 
-    rn_op clas clas_tyvar sig@(ClassOpSig op _ ty locn)
+    rn_op clas clas_tyvars sig@(ClassOpSig op maybe_dm ty locn)
       = pushSrcLocRn locn $
        lookupBndrRn op                         `thenRn` \ op_name ->
-       rnHsSigType (\sty -> ppr sty op) ty     `thenRn` \ new_ty  ->
+       rnHsSigType (quotes (ppr op)) ty        `thenRn` \ new_ty  ->
 
-               -- Call up interface info for default method, if such info exists
+               -- Make the default-method name
        let
            dm_occ = prefixOccName SLIT("$m") (rdrNameOcc op)
        in
-        newSysName dm_occ Exported locn                `thenRn` \ dm_name ->
-       setModeRn (InterfaceMode Optional) (
-            addOccurrenceName dm_name
-       )                                               `thenRn_`
-
-               -- Checks.....
+       getModuleRn                     `thenRn` \ mod_name ->
+       getModeRn                       `thenRn` \ mode ->
+       (case (mode, maybe_dm) of 
+           (SourceMode, _) | op `elem` meth_rdr_names
+               ->      -- There's an explicit method decl
+                  newLocallyDefinedGlobalName mod_name dm_occ 
+                                              (\_ -> Exported) locn    `thenRn` \ dm_name ->
+                  returnRn (Just dm_name)
+
+           (InterfaceMode _ _, Just _) 
+               ->      -- Imported class that has a default method decl
+                   newImportedGlobalName mod_name dm_occ (ifaceFlavour clas)   `thenRn` \ dm_name ->
+                   addOccurrenceName dm_name                                   `thenRn_`
+                   returnRn (Just dm_name)
+
+           other -> returnRn Nothing
+       )                                       `thenRn` \ maybe_dm_name ->
+
+               -- Check that each class tyvar appears in op_ty
        let
            (ctxt, op_ty) = case new_ty of
                                HsForAllTy tvs ctxt op_ty -> (ctxt, op_ty)
                                other                     -> ([], new_ty)
-           ctxt_fvs  = extractCtxtTyNames ctxt
-           op_ty_fvs = extractHsTyNames op_ty          -- Includes tycons/classes but we
-                                                       -- don't care about that
-       in
-               -- Check that class tyvar appears in op_ty
-        checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
-               (classTyVarNotInOpTyErr clas_tyvar sig)
-                                                        `thenRn_`
+           ctxt_fvs  = extractHsCtxtTyNames ctxt       -- Includes tycons/classes but we
+           op_ty_fvs = extractHsTyNames op_ty          -- don't care about that
 
-               -- Check that class tyvar *doesn't* appear in the sig's context
-        checkRn (not (clas_tyvar `elemNameSet` ctxt_fvs))
-               (classTyVarInOpCtxtErr clas_tyvar sig)
-                                                        `thenRn_`
+           check_in_op_ty clas_tyvar = checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
+                                               (classTyVarNotInOpTyErr clas_tyvar sig)
+       in
+        mapRn check_in_op_ty clas_tyvars                `thenRn_`
 
-       returnRn (ClassOpSig op_name dm_name new_ty locn)
+       returnRn (ClassOpSig op_name maybe_dm_name new_ty locn)
 \end{code}
 
 
@@ -231,51 +234,55 @@ rnDecl (ClD (ClassDecl context cname tyvar sigs mbinds pragmas src_loc))
 \begin{code}
 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
   = pushSrcLocRn src_loc $
-    rnHsSigType (\sty -> text "an instance decl") inst_ty      `thenRn` \ inst_ty' ->
+    rnHsSigType (text "an instance decl") inst_ty      `thenRn` \ inst_ty' ->
 
 
        -- Rename the bindings
        -- NB meth_names can be qualified!
     checkDupNames meth_doc meth_names          `thenRn_`
     rnMethodBinds mbinds                       `thenRn` \ mbinds' ->
-    mapRn rn_uprag uprags                      `thenRn` \ new_uprags ->
-
-    newDfunName maybe_dfun src_loc             `thenRn` \ dfun_name ->
-    addOccurrenceName dfun_name                        `thenRn_`
+    let 
+       binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
+    in
+    renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
+   
+    let
+     -- We use the class name and the name of the first
+     -- type constructor the class is applied to.
+     (cl_nm, tycon_nm) = mkDictPrefix inst_ty'
+     
+     mkDictPrefix (MonoDictTy cl tys) = 
+        case tys of
+         []     -> (c_nm, nilOccName )
+         (ty:_) -> (c_nm, getInstHeadTy ty)
+       where
+        c_nm = nameOccName (getName cl)
+
+     mkDictPrefix (HsPreForAllTy _ ty) = mkDictPrefix ty
+     mkDictPrefix (HsForAllTy _ _ ty)  = mkDictPrefix ty  -- can this 
+     mkDictPrefix _                   = (nilOccName, nilOccName)
+
+     getInstHeadTy t 
+      = case t of
+          MonoTyVar tv    -> nameOccName (getName tv)
+          MonoTyApp t _   -> getInstHeadTy t
+         _               -> nilOccName
+           -- I cannot see how the rest of HsType constructors
+           -- can occur, but this isn't really a failure condition,
+           -- so we return silently.
+
+     nilOccName = (VarOcc _NIL_) -- ToDo: add OccName constructor fun for this.
+    in
+    newDfunName cl_nm tycon_nm maybe_dfun src_loc  `thenRn` \ dfun_name ->
+    addOccurrenceName dfun_name                           `thenRn_`
                        -- The dfun is not optional, because we use its version number
                        -- to identify the version of the instance declaration
 
        -- The typechecker checks that all the bindings are for the right class.
     returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc))
   where
-    meth_doc sty = text "the bindings in an instance declaration"
+    meth_doc = text "the bindings in an instance declaration"
     meth_names   = bagToList (collectMonoBinders mbinds)
-
-    rn_uprag (SpecSig op ty using locn)
-      = pushSrcLocRn src_loc $
-       lookupBndrRn op                         `thenRn` \ op_name ->
-       rnHsSigType (\sty -> ppr sty op) ty     `thenRn` \ new_ty ->
-       rn_using using                          `thenRn` \ new_using ->
-       returnRn (SpecSig op_name new_ty new_using locn)
-
-    rn_uprag (InlineSig op locn)
-      = pushSrcLocRn locn $
-       lookupBndrRn op                 `thenRn` \ op_name ->
-       returnRn (InlineSig op_name locn)
-
-    rn_uprag (DeforestSig op locn)
-      = pushSrcLocRn locn $
-       lookupBndrRn op                 `thenRn` \ op_name ->
-       returnRn (DeforestSig op_name locn)
-
-    rn_uprag (MagicUnfoldingSig op str locn)
-      = pushSrcLocRn locn $
-       lookupBndrRn op                 `thenRn` \ op_name ->
-       returnRn (MagicUnfoldingSig op_name str locn)
-
-    rn_using Nothing  = returnRn Nothing
-    rn_using (Just v) = lookupOccRn v  `thenRn` \ new_v ->
-                       returnRn (Just new_v)
 \end{code}
 
 %*********************************************************
@@ -294,6 +301,28 @@ rnDecl (DefD (DefaultDecl tys src_loc))
 
 %*********************************************************
 %*                                                     *
+\subsection{Foreign declarations}
+%*                                                     *
+%*********************************************************
+
+\begin{code}
+rnDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
+  = pushSrcLocRn src_loc $
+    lookupBndrRn name                  `thenRn` \ name' ->
+    (if is_export then
+        addImplicitOccRn name'
+     else
+       returnRn name')                 `thenRn_`
+    rnHsSigType fo_decl_msg ty         `thenRn` \ ty' ->
+    returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc))
+ where
+  fo_decl_msg = ptext SLIT("a foreign declaration")
+  is_export   = not (maybeToBool imp_exp) && not (isDynamic ext_nm)
+
+\end{code}
+
+%*********************************************************
+%*                                                     *
 \subsection{Support code for type/data declarations}
 %*                                                     *
 %*********************************************************
@@ -355,7 +384,7 @@ rnConDetails con locn (RecCon fields)
     mapRn rnField fields                       `thenRn` \ new_fields ->
     returnRn (RecCon new_fields)
   where
-    fld_doc sty = text "the fields of constructor" <> ppr sty con
+    fld_doc = text "the fields of constructor" <> ppr con
     field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
 
 rnField (names, ty)
@@ -394,34 +423,43 @@ checkConName name
 %*********************************************************
 
 \begin{code}
-rnHsSigType :: (PprStyle -> Doc) -> RdrNameHsType -> RnMS s RenamedHsType 
+rnHsSigType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType 
        -- rnHsSigType is used for source-language type signatures,
        -- which use *implicit* universal quantification.
 
+-- Given the signature  C => T  we universally quantify over FV(T) \ {in-scope-tyvars} 
+-- 
+-- We insist that the universally quantified type vars is a superset of FV(C)
+-- It follows that FV(T) is a superset of FV(C), so that the context constrains
+-- no type variables that don't appear free in the tau-type part.
+
 rnHsSigType doc_str full_ty@(HsPreForAllTy ctxt ty)    -- From source code (no kinds on tyvars)
-  = getNameEnv         `thenRn` \ name_env ->
+  = getLocalNameEnv            `thenRn` \ name_env ->
     let
-       mentioned_tyvars = extractHsTyVars full_ty
-       forall_tyvars    = filter not_in_scope mentioned_tyvars
-       not_in_scope tv  = case lookupFM name_env tv of
-                                   Nothing -> True
-                                   Just _  -> False
-
-       non_foralld_constrained = [tv | (clas, ty) <- ctxt,
-                                       tv <- extractHsTyVars ty,
-                                       not (tv `elem` forall_tyvars)
-                                 ]
+       mentioned_tyvars = extractHsTyVars ty
+       forall_tyvars    = filter (not . in_scope) mentioned_tyvars
+       in_scope tv      = maybeToBool (lookupFM name_env tv)
+
+       constrained_tyvars            = extractHsCtxtTyVars ctxt
+       constrained_and_in_scope      = filter in_scope constrained_tyvars
+       constrained_and_not_mentioned = filter (not . (`elem` mentioned_tyvars)) constrained_tyvars
+
+       -- Zap the context if there's a problem, to avoid duplicate error message.
+       ctxt' | null constrained_and_in_scope && null constrained_and_not_mentioned = ctxt
+             | otherwise = []
     in
-    checkRn (null non_foralld_constrained)
-           (ctxtErr sig_doc non_foralld_constrained)   `thenRn_`
+    checkRn (null constrained_and_in_scope)
+           (ctxtErr1 sig_doc constrained_and_in_scope) `thenRn_`
+    checkRn (null constrained_and_not_mentioned)
+           (ctxtErr2 sig_doc constrained_and_not_mentioned ty) `thenRn_`
 
     (bindTyVarsRn sig_doc (map UserTyVar forall_tyvars)        $ \ new_tyvars ->
-     rnContext ctxt                                    `thenRn` \ new_ctxt ->
+     rnContext ctxt'                                   `thenRn` \ new_ctxt ->
      rnHsType ty                                       `thenRn` \ new_ty ->
      returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
     )
   where
-    sig_doc sty = text "the type signature for" <+> doc_str sty
+    sig_doc = text "the type signature for" <+> doc_str
                             
 
 rnHsSigType doc_str other_ty = rnHsType other_ty
@@ -432,9 +470,9 @@ rnHsType (HsForAllTy tvs ctxt ty)           -- From an interface file (tyvars may be kind
 
 rnHsType full_ty@(HsPreForAllTy ctxt ty)       -- A (context => ty) embedded in a type.
                                                -- Universally quantify over tyvars in context
-  = getNameEnv         `thenRn` \ name_env ->
+  = getLocalNameEnv            `thenRn` \ name_env ->
     let
-       forall_tyvars = foldr unionLists [] (map (extractHsTyVars . snd) ctxt)
+       forall_tyvars = extractHsCtxtTyVars ctxt
     in
     rn_poly_help (map UserTyVar forall_tyvars) ctxt ty
 
@@ -460,10 +498,10 @@ rnHsType (MonoTyApp ty1 ty2)
     rnHsType ty2               `thenRn` \ ty2' ->
     returnRn (MonoTyApp ty1' ty2')
 
-rnHsType (MonoDictTy clas ty)
+rnHsType (MonoDictTy clas tys)
   = lookupOccRn clas           `thenRn` \ clas' ->
-    rnHsType ty                        `thenRn` \ ty' ->
-    returnRn (MonoDictTy clas' ty')
+    mapRn rnHsType tys         `thenRn` \ tys' ->
+    returnRn (MonoDictTy clas' tys')
 
 rn_poly_help :: [HsTyVar RdrName]              -- Universally quantified tyvars
             -> RdrNameContext
@@ -475,7 +513,7 @@ rn_poly_help tyvars ctxt ty
     rnHsType ty                                                `thenRn` \ new_ty ->
     returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
   where
-    sig_doc sty = text "a nested for-all type"
+    sig_doc = text "a nested for-all type"
 \end{code}
 
 
@@ -487,22 +525,21 @@ rnContext  ctxt
     let
        (_, dup_asserts) = removeDups cmp_assert result
        (alls, theta)    = partition (\(c,_) -> c == allClass_NAME) result
-       non_tyvar_alls   = [(c,t) | (c,t) <- alls, not (is_tyvar t)]
     in
 
        -- Check for duplicate assertions
        -- If this isn't an error, then it ought to be:
-    mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts `thenRn_`
+    mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts   `thenRn_`
 
        -- Check for All constraining a non-type-variable
-    mapRn (addWarnRn . allOfNonTyVar) non_tyvar_alls   `thenRn_`
+    mapRn check_All alls                                       `thenRn_`
     
        -- Done.  Return a theta omitting all the "All" constraints.
        -- They have done done their work by ensuring that we universally
        -- quantify over their tyvar.
     returnRn theta
   where
-    rn_ctxt (clas, ty)
+    rn_ctxt (clas, tys)
       =                -- Mini hack here.  If the class is our pseudo-class "All",
                -- then we don't want to record it as an occurrence, otherwise
                -- we try to slurp it in later and it doesn't really exist at all.
@@ -513,14 +550,15 @@ rnContext  ctxt
         else
                returnRn clas_name
        )                       `thenRn_`
-       rnHsType ty             `thenRn` \ ty' ->
-       returnRn (clas_name, ty')
+       mapRn rnHsType tys      `thenRn` \ tys' ->
+       returnRn (clas_name, tys')
 
-    cmp_assert (c1,ty1) (c2,ty2)
-      = (c1 `cmp` c2) `thenCmp` (cmpHsType cmp ty1 ty2)
 
-    is_tyvar (MonoTyVar _) = True
-    is_tyvar other         = False
+    cmp_assert (c1,tys1) (c2,tys2)
+      = (c1 `compare` c2) `thenCmp` (cmpHsTypes compare tys1 tys2)
+
+    check_All (c, [MonoTyVar _]) = returnRn () -- OK!
+    check_All assertion                 = addErrRn (wierdAllErr assertion)
 \end{code}
 
 
@@ -541,20 +579,26 @@ rnIdInfo (HsArity arity)  = returnRn (HsArity arity)
 rnIdInfo (HsUpdate update)     = returnRn (HsUpdate update)
 rnIdInfo (HsFBType fb)         = returnRn (HsFBType fb)
 rnIdInfo (HsArgUsage au)       = returnRn (HsArgUsage au)
-rnIdInfo (HsDeforest df)       = returnRn (HsDeforest df)
+rnIdInfo (HsSpecialise tyvars tys expr)
+  = bindTyVarsRn doc tyvars    $ \ tyvars' ->
+    rnCoreExpr expr            `thenRn` \ expr' ->
+    mapRn rnHsType tys         `thenRn` \ tys' ->
+    returnRn (HsSpecialise tyvars' tys' expr')
+  where
+    doc = text "Specialise in interface pragma"
+    
 
-rnStrict (StrictnessInfo demands (Just (worker,cons)))
+rnStrict (HsStrictnessInfo demands (Just (worker,cons)))
        -- The sole purpose of the "cons" field is so that we can mark the constructors
        -- needed to build the wrapper as "needed", so that their data type decl will be
        -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
   = lookupOccRn worker                 `thenRn` \ worker' ->
     mapRn lookupOccRn cons             `thenRn_` 
-    returnRn (StrictnessInfo demands (Just (worker',[])))
+    returnRn (HsStrictnessInfo demands (Just (worker',[])))
 
 -- Boring, but necessary for the type checker.
-rnStrict (StrictnessInfo demands Nothing) = returnRn (StrictnessInfo demands Nothing)
-rnStrict BottomGuaranteed                = returnRn BottomGuaranteed
-rnStrict NoStrictnessInfo                = returnRn NoStrictnessInfo
+rnStrict (HsStrictnessInfo demands Nothing) = returnRn (HsStrictnessInfo demands Nothing)
+rnStrict HsBottom                        = returnRn HsBottom
 \end{code}
 
 UfCore expressions.
@@ -586,15 +630,10 @@ rnCoreExpr (UfCase scrut alts)
     rnCoreAlts alts            `thenRn` \ alts' ->
     returnRn (UfCase scrut' alts')
 
-rnCoreExpr (UfSCC cc expr) 
-  = rnCoreExpr expr            `thenRn` \ expr' ->
-    returnRn  (UfSCC cc expr') 
-
-rnCoreExpr(UfCoerce coercion ty body)
-  = rnCoercion coercion                `thenRn` \ coercion' ->
-    rnHsType ty                        `thenRn` \ ty' ->
-    rnCoreExpr body            `thenRn` \ body' ->
-    returnRn (UfCoerce coercion' ty' body')
+rnCoreExpr (UfNote note expr) 
+  = rnNote note                        `thenRn` \ note' ->
+    rnCoreExpr expr            `thenRn` \ expr' ->
+    returnRn  (UfNote note' expr') 
 
 rnCoreExpr (UfLam bndr body)
   = rnCoreBndr bndr            $ \ bndr' ->
@@ -626,10 +665,6 @@ rnCoreBndr (UfTyBinder name kind) thing_inside
   = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
     thing_inside (UfTyBinder name' kind)
     
-rnCoreBndr (UfUsageBinder name) thing_inside
-  = bindLocalsRn "unfolding usage" [name] $ \ [name'] ->
-    thing_inside (UfUsageBinder name')
-
 rnCoreBndrs bndrs thing_inside         -- Expect them all to be ValBinders
   = mapRn rnHsType tys                 `thenRn` \ tys' ->
     bindLocalsRn "unfolding value" names $ \ names' ->
@@ -645,8 +680,7 @@ rnCoreBndrNamess names thing_inside
 
 \begin{code}
 rnCoreArg (UfVarArg v)  = lookupOccRn v        `thenRn` \ v' -> returnRn (UfVarArg v')
-rnCoreArg (UfUsageArg u) = lookupOccRn u       `thenRn` \ u' -> returnRn (UfUsageArg u')
-rnCoreArg (UfTyArg ty)  = rnHsType ty                  `thenRn` \ ty' -> returnRn (UfTyArg ty')
+rnCoreArg (UfTyArg ty)  = rnHsType ty          `thenRn` \ ty' -> returnRn (UfTyArg ty')
 rnCoreArg (UfLitArg lit) = returnRn (UfLitArg lit)
 
 rnCoreAlts (UfAlgAlts alts deflt)
@@ -672,8 +706,12 @@ rnCoreDefault (UfBindDefault bndr rhs) = bindLocalsRn "unfolding default" [bndr]
                                         rnCoreExpr rhs                                 `thenRn` \ rhs' ->
                                         returnRn (UfBindDefault bndr' rhs')
 
-rnCoercion (UfIn  n) = lookupOccRn n `thenRn` \ n' -> returnRn (UfIn  n')
-rnCoercion (UfOut n) = lookupOccRn n `thenRn` \ n' -> returnRn (UfOut n')
+rnNote (UfCoerce ty)
+  = rnHsType ty                        `thenRn` \ ty' ->
+    returnRn (UfCoerce ty')
+
+rnNote (UfSCC cc)   = returnRn (UfSCC cc)
+rnNote UfInlineCall = returnRn UfInlineCall
 
 rnCorePrim (UfOtherOp op) 
   = lookupOccRn op     `thenRn` \ op' ->
@@ -692,34 +730,37 @@ rnCorePrim (UfCCallOp str casm gc arg_tys res_ty)
 %*********************************************************
 
 \begin{code}
-derivingNonStdClassErr clas sty
-  = hsep [ptext SLIT("non-standard class in deriving:"), ppr sty clas]
-
-classTyVarNotInOpTyErr clas_tyvar sig sty
-  = hang (hcat [ptext SLIT("Class type variable `"), 
-                      ppr sty clas_tyvar, 
-                      ptext SLIT("' does not appear in method signature:")])
-        4 (ppr sty sig)
-
-classTyVarInOpCtxtErr clas_tyvar sig sty
-  = hang (hcat [ ptext SLIT("Class type variable `"), ppr sty clas_tyvar, 
-                       ptext SLIT("' present in method's local overloading context:")])
-        4 (ppr sty sig)
-
-dupClassAssertWarn ctxt dups sty
-  = hang (hcat [ptext SLIT("Duplicate class assertion `"), 
-                      ppr sty dups, 
-                      ptext SLIT("' in context:")])
-        4 (ppr sty ctxt)
-
-badDataCon name sty
-   = hsep [ptext SLIT("Illegal data constructor name:"), ppr sty name]
-
-allOfNonTyVar ty sty
-  = hsep [ptext SLIT("`All' applied to a non-type variable:"), ppr sty ty]
-
-ctxtErr doc tyvars sty
-  = hsep [ptext SLIT("Context constrains type variable(s)"), 
-         hsep (punctuate comma (map (ppr sty) tyvars))]
-    $$ nest 4 (ptext SLIT("in") <+> doc sty)
+derivingNonStdClassErr clas
+  = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
+
+classTyVarNotInOpTyErr clas_tyvar sig
+  = hang (hsep [ptext SLIT("Class type variable"),
+                      quotes (ppr clas_tyvar),
+                      ptext SLIT("does not appear in method signature")])
+        4 (ppr sig)
+
+dupClassAssertWarn ctxt (assertion : dups)
+  = sep [hsep [ptext SLIT("Duplicate class assertion"), 
+              quotes (pprClassAssertion assertion),
+              ptext SLIT("in the context:")],
+        nest 4 (pprContext ctxt)]
+
+badDataCon name
+   = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
+
+wierdAllErr assertion
+  = ptext SLIT("Mal-formed use of `All':") <+> pprClassAssertion assertion
+
+ctxtErr1 doc tyvars
+  = hsep [ptext SLIT("Context constrains in-scope type variable(s)"), 
+         pprQuotedList tyvars]
+    $$
+    nest 4 (ptext SLIT("in") <+> doc)
+
+ctxtErr2 doc tyvars ty
+  = (ptext SLIT("Context constrains type variable(s)")
+       <+> pprQuotedList tyvars)
+    $$
+    nest 4 (vcat [ptext SLIT("that do not appear in") <+> quotes (ppr ty),
+                 ptext SLIT("in") <+> doc])
 \end{code}