diff options
author | Austin Seipp <austin@well-typed.com> | 2014-12-03 12:42:50 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-12-03 12:42:50 -0600 |
commit | 9fc4382ced4357b03b169c36934d7acd3ac4dd59 (patch) | |
tree | 9364bed341f1de55a45f3573c602d0905863cb6c /compiler/rename | |
parent | dc00fb1b5e75fda17384af612a98a8c99f874cff (diff) | |
download | haskell-9fc4382ced4357b03b169c36934d7acd3ac4dd59.tar.gz |
compiler: de-lhs rename/
Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnBinds.hs (renamed from compiler/rename/RnBinds.lhs) | 126 | ||||
-rw-r--r-- | compiler/rename/RnEnv.hs (renamed from compiler/rename/RnEnv.lhs) | 177 | ||||
-rw-r--r-- | compiler/rename/RnExpr.hs (renamed from compiler/rename/RnExpr.lhs) | 121 | ||||
-rw-r--r-- | compiler/rename/RnExpr.hs-boot (renamed from compiler/rename/RnExpr.lhs-boot) | 7 | ||||
-rw-r--r-- | compiler/rename/RnNames.hs (renamed from compiler/rename/RnNames.lhs) | 135 | ||||
-rw-r--r-- | compiler/rename/RnPat.hs (renamed from compiler/rename/RnPat.lhs) | 197 | ||||
-rw-r--r-- | compiler/rename/RnSource.hs (renamed from compiler/rename/RnSource.lhs) | 223 | ||||
-rw-r--r-- | compiler/rename/RnSplice.hs (renamed from compiler/rename/RnSplice.lhs) | 45 | ||||
-rw-r--r-- | compiler/rename/RnSplice.hs-boot (renamed from compiler/rename/RnSplice.lhs-boot) | 2 | ||||
-rw-r--r-- | compiler/rename/RnTypes.hs (renamed from compiler/rename/RnTypes.lhs) | 84 |
10 files changed, 520 insertions, 597 deletions
diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.hs index cdb211259b..1af93f35d2 100644 --- a/compiler/rename/RnBinds.lhs +++ b/compiler/rename/RnBinds.hs @@ -1,14 +1,14 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnBinds]{Renaming and dependency analysis of bindings} This module does renaming and dependency analysis on value bindings in the abstract syntax. It does {\em not} do cycle-checks on class or type-synonym declarations; those cannot be done at this stage because they may be affected by renaming (which isn't fully worked out yet). +-} -\begin{code} {-# LANGUAGE CPP #-} module RnBinds ( @@ -53,8 +53,8 @@ import Control.Monad #if __GLASGOW_HASKELL__ < 709 import Data.Traversable ( traverse ) #endif -\end{code} +{- -- ToDo: Put the annotations into the monad, so that they arrive in the proper -- place and can be used when complaining. @@ -82,11 +82,11 @@ within one @MonoBinds@, so that unique-Int plumbing is done explicitly (heavy monad machinery not needed). -%************************************************************************ -%* * -%* naming conventions * -%* * -%************************************************************************ +************************************************************************ +* * +* naming conventions * +* * +************************************************************************ \subsection[name-conventions]{Name conventions} @@ -109,11 +109,11 @@ a set of variables defined in @Exp@ is written @dvExp@ a set of variables free in @Exp@ is written @fvExp@ \end{itemize} -%************************************************************************ -%* * -%* analysing polymorphic bindings (HsBindGroup, HsBind) -%* * -%************************************************************************ +************************************************************************ +* * +* analysing polymorphic bindings (HsBindGroup, HsBind) +* * +************************************************************************ \subsubsection[dep-HsBinds]{Polymorphic bindings} @@ -155,13 +155,13 @@ instance declarations. It expects only to see @FunMonoBind@s, and it expects the global environment to contain bindings for the binders (which are all class operations). -%************************************************************************ -%* * +************************************************************************ +* * \subsubsection{ Top-level bindings} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} -- for top-level bindings, we need to make top-level names, -- so we have a different entry point than for local bindings rnTopBindsLHS :: MiniFixityEnv @@ -186,16 +186,15 @@ rnTopBindsBoot (ValBindsIn mbinds sigs) ; (sigs', fvs) <- renameSigs HsBootCtxt sigs ; return (ValBindsOut [] sigs', usesOnly fvs) } rnTopBindsBoot b = pprPanic "rnTopBindsBoot" (ppr b) -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * HsLocalBinds -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnLocalBindsAndThen :: HsLocalBinds RdrName -> (HsLocalBinds Name -> RnM (result, FreeVars)) -> RnM (result, FreeVars) @@ -223,16 +222,15 @@ rnIPBind :: IPBind RdrName -> RnM (IPBind Name, FreeVars) rnIPBind (IPBind ~(Left n) expr) = do (expr',fvExpr) <- rnLExpr expr return (IPBind (Left n) expr', fvExpr) -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * ValBinds -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} -- Renaming local binding groups -- Does duplicate/shadow check rnLocalValBindsLHS :: MiniFixityEnv @@ -678,9 +676,8 @@ mkSigTvFn sigs , L _ name <- names] -- Note the pattern-match on "Explicit"; we only bind -- type variables from signatures with an explicit top-level for-all -\end{code} - +{- @rnMethodBinds@ is used for the method bindings of a class and an instance declaration. Like @rnBinds@ but without dependency analysis. @@ -695,8 +692,8 @@ and unless @op@ occurs we won't treat the type signature of @op@ in the class decl for @Foo@ as a source of instance-decl gates. But we should! Indeed, in many ways the @op@ in an instance decl is just like an occurrence, not a binder. +-} -\begin{code} rnMethodBinds :: Name -- Class name -> (Name -> [Name]) -- Signature tyvar function -> LHsBinds RdrName @@ -757,26 +754,24 @@ rnMethodBind _ _ (L loc bind@(PatSynBind {})) = do return (emptyBag, emptyFVs) rnMethodBind _ _ b = pprPanic "rnMethodBind" (ppr b) -\end{code} - - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection[dep-Sigs]{Signatures (and user-pragmas for values)} -%* * -%************************************************************************ +* * +************************************************************************ @renameSigs@ checks for: \begin{enumerate} \item more than one sig for one thing; \item signatures given for things not bound here; \end{enumerate} -% + At the moment we don't gather free-var info from the types in signatures. We'd only need this if we wanted to report unused tyvars. +-} -\begin{code} renameSigs :: HsSigCtxt -> [LSig RdrName] -> RnM ([LSig Name], FreeVars) @@ -946,16 +941,15 @@ checkDupMinimalSigs sigs = case filter isMinimalLSig sigs of minSigs@(_:_:_) -> dupMinimalSigErr minSigs _ -> return () -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Match} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnMatchGroup :: Outputable (body RdrName) => HsMatchContext Name -> (Located (body RdrName) -> RnM (Located (body Name), FreeVars)) -> MatchGroup RdrName (Located (body RdrName)) @@ -1006,16 +1000,15 @@ resSigErr ctxt match ty , nest 2 $ ptext (sLit "Result signatures are no longer supported in pattern matches") , pprMatchInCtxt ctxt match ] -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{Guarded right-hand sides (GRHSs)} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnGRHSs :: HsMatchContext Name -> (Located (body RdrName) -> RnM (Located (body Name), FreeVars)) -> GRHSs RdrName (Located (body RdrName)) @@ -1051,15 +1044,15 @@ rnGRHS' ctxt rnBody (GRHS guards rhs) is_standard_guard [] = True is_standard_guard [L _ (BodyStmt _ _ _ _)] = True is_standard_guard _ = False -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Error messages} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} dupSigDeclErr :: [(Located RdrName, Sig RdrName)] -> RnM () dupSigDeclErr pairs@((L loc name, sig) : _) = addErrAt loc $ @@ -1113,4 +1106,3 @@ dupMinimalSigErr sigs@(L loc _ : _) , ptext (sLit "at") <+> vcat (map ppr $ sort $ map getLoc sigs) , ptext (sLit "Combine alternative minimal complete definitions with `|'") ] dupMinimalSigErr [] = panic "dupMinimalSigErr" -\end{code} diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.hs index 7e096c0648..0cea309208 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.hs @@ -1,9 +1,9 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-2006 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-2006 + \section[RnEnv]{Environment manipulation for the renamer monad} +-} -\begin{code} {-# LANGUAGE CPP #-} module RnEnv ( @@ -24,12 +24,12 @@ module RnEnv ( lookupSubBndrGREs, lookupConstructorFields, lookupSyntaxName, lookupSyntaxNames, lookupIfThenElse, lookupGreRn, lookupGreRn_maybe, - lookupGreLocalRn_maybe, + lookupGreLocalRn_maybe, getLookupOccRn, addUsedRdrNames, newLocalBndrRn, newLocalBndrsRn, bindLocalNames, bindLocalNamesFV, - MiniFixityEnv, + MiniFixityEnv, addLocalFixities, bindLocatedLocalsFV, bindLocatedLocalsRn, extendTyVarEnvFVRn, @@ -76,13 +76,13 @@ import Control.Monad import Data.List import qualified Data.Set as Set import Constants ( mAX_TUPLE_SIZE ) -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * Source-code binders -%* * -%********************************************************* +* * +********************************************************* Note [Signature lazy interface loading] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -141,8 +141,8 @@ warning until you use the identifier further downstream. This would require adjusting addUsedRdrName so that during signature compilation, we do not report deprecation warnings for LocalDef. See also Note [Handling of deprecations] +-} -\begin{code} newTopSrcBinder :: Located RdrName -> RnM Name newTopSrcBinder (L loc rdr_name) | Just name <- isExact_maybe rdr_name @@ -232,13 +232,13 @@ newTopSrcBinder (L loc rdr_name) -- Normal case do { this_mod <- getModule ; newGlobalBinder this_mod (rdrNameOcc rdr_name) loc } } -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * Source code occurrences -%* * -%********************************************************* +* * +********************************************************* Looking up a name in the RnEnv. @@ -253,8 +253,8 @@ The latter two mean that we are not just looking for a *syntactically-infix* declaration, but one that uses an operator OccName. We use OccName.isSymOcc to detect that case, which isn't terribly efficient, but there seems to be no better way. +-} -\begin{code} lookupTopBndrRn :: RdrName -> RnM Name lookupTopBndrRn n = do nopt <- lookupTopBndrRn_maybe n case nopt of @@ -366,7 +366,7 @@ lookupExactOcc_either name [gre] -> return (Right (gre_name gre)) _ -> return (Left dup_nm_err) - -- We can get more than one GRE here, if there are multiple + -- We can get more than one GRE here, if there are multiple -- bindings for the same name. Sometimes they are caught later -- by findLocalDupsRdrEnv, like in this example (Trac #8932): -- $( [d| foo :: a->a; foo x = x |]) @@ -528,8 +528,8 @@ lookupSubBndrGREs env parent rdr_name parent_is p (GRE { gre_par = ParentIs p' }) = p == p' parent_is _ _ = False -\end{code} +{- Note [Family instance binders] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider @@ -643,8 +643,8 @@ we'll miss the fact that the qualified import is redundant. -------------------------------------------------- -- Occurrences -------------------------------------------------- +-} -\begin{code} getLookupOccRn :: RnM (Name -> Maybe Name) getLookupOccRn = do local_env <- getLocalRdrEnv @@ -707,8 +707,8 @@ lookup_demoted rdr_name where suggest_dk = ptext (sLit "A data constructor of that name is in scope; did you mean DataKinds?") -\end{code} +{- Note [Demotion] ~~~~~~~~~~~~~~~ When the user writes: @@ -725,8 +725,8 @@ its namespace to DataName and do a second lookup. The final result (after the renamer) will be: HsTyVar ("Zero", DataName) +-} -\begin{code} -- Use this version to get tracing -- -- lookupOccRn_maybe, lookupOccRn_maybe' :: RdrName -> RnM (Maybe Name) @@ -827,13 +827,13 @@ lookupGreRn_help rdr_name lookup ; return (Just gre) } gres -> do { addNameClashErrRn rdr_name gres ; return (Just (head gres)) } } -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * Deprecations -%* * -%********************************************************* +* * +********************************************************* Note [Handling of deprecations] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -850,8 +850,8 @@ Note [Handling of deprecations] - the ".." completion for records - the ".." in an export item 'T(..)' - the things exported by a module export 'module M' +-} -\begin{code} addUsedRdrName :: Bool -> GlobalRdrElt -> RdrName -> RnM () -- Record usage of imported RdrNames addUsedRdrName warnIfDeprec gre rdr @@ -903,8 +903,8 @@ lookupImpDeprec iface gre case gre_par gre of -- or its parent, is warn'd ParentIs p -> mi_warn_fn iface p NoParent -> Nothing -\end{code} +{- Note [Used names with interface not loaded] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's (just) possible to find a used @@ -925,11 +925,11 @@ In both cases we simply don't permit deprecations; this is, after all, wired-in stuff. -%********************************************************* -%* * +********************************************************* +* * GHCi support -%* * -%********************************************************* +* * +********************************************************* A qualified name on the command line can refer to any module at all: we try to load the interface if we don't already have it, just @@ -945,8 +945,8 @@ Note [Safe Haskell and GHCi] We DONT do this Safe Haskell as we need to check imports. We can and should instead check the qualified import but at the moment this requires some refactoring so leave as a TODO +-} -\begin{code} lookupQualifiedNameGHCi :: DynFlags -> Bool -> RdrName -> RnM (Maybe Name) lookupQualifiedNameGHCi dflags is_ghci rdr_name | Just (mod,occ) <- isQual_maybe rdr_name @@ -974,8 +974,8 @@ lookupQualifiedNameGHCi dflags is_ghci rdr_name = return Nothing where doc = ptext (sLit "Need to find") <+> ppr rdr_name -\end{code} +{- Note [Looking up signature names] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lookupSigOccRn is used for type signatures and pragmas @@ -1016,8 +1016,8 @@ data HsSigCtxt = ... | TopSigCtxt NameSet Bool | .... f :: C a => a -> a -- No, not ok class C a where f :: a -> a +-} -\begin{code} data HsSigCtxt = TopSigCtxt NameSet Bool -- At top level, binding these names -- See Note [Signatures for top level things] @@ -1137,8 +1137,8 @@ dataTcOccs rdr_name where occ = rdrNameOcc rdr_name rdr_name_tc = setRdrNameSpace rdr_name tcName -\end{code} +{- Note [dataTcOccs and Exact Names] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Exact RdrNames can occur in code generated by Template Haskell, and generally @@ -1155,11 +1155,11 @@ the list type constructor. Note that setRdrNameSpace on an Exact name requires the Name to be External, which it always is for built in syntax. -%********************************************************* -%* * +********************************************************* +* * Fixities -%* * -%********************************************************* +* * +********************************************************* Note [Fixity signature lookup] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1180,8 +1180,8 @@ well as the original namespace. The extended lookup is also used in other places, like resolution of deprecation declarations, and lookup of names in GHCi. +-} -\begin{code} -------------------------------- type MiniFixityEnv = FastStringEnv (Located Fixity) -- Mini fixity env for the names we're about @@ -1208,8 +1208,8 @@ addLocalFixities mini_fix_env names thing_inside Nothing -> Nothing where occ = nameOccName name -\end{code} +{- -------------------------------- lookupFixity is a bit strange. @@ -1223,12 +1223,12 @@ lookupFixity is a bit strange. or Local/Exported (everything else) (See notes with RnNames.getLocalDeclBinders for why we have this split.) We put them all in the local fixity environment +-} -\begin{code} lookupFixityRn :: Name -> RnM Fixity lookupFixityRn name | isUnboundName name - = return (Fixity minPrecedence InfixL) + = return (Fixity minPrecedence InfixL) -- Minimise errors from ubound names; eg -- a>0 `foo` b>0 -- where 'foo' is not in scope, should not give an error (Trac #7937) @@ -1274,10 +1274,9 @@ lookupFixityRn name lookupTyFixityRn :: Located Name -> RnM Fixity lookupTyFixityRn (L _ n) = lookupFixityRn n -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * Rebindable names Dealing with rebindable syntax is driven by the Opt_RebindableSyntax dynamic flag. @@ -1285,8 +1284,8 @@ lookupTyFixityRn (L _ n) = lookupFixityRn n In "deriving" code we don't want to use rebindable syntax so we switch off the flag locally -%* * -%************************************************************************ +* * +************************************************************************ Haskell 98 says that when you say "3" you get the "fromInteger" from the Standard Prelude, regardless of what is in scope. However, to experiment @@ -1314,8 +1313,8 @@ name if Opt_NoImplicitPrelude is on. That is what lookupSyntaxName does. We treat the orignal (standard) names as free-vars too, because the type checker checks the type of the user thing against the type of the standard thing. +-} -\begin{code} lookupIfThenElse :: RnM (Maybe (SyntaxExpr Name), FreeVars) -- Different to lookupSyntaxName because in the non-rebindable -- case we desugar directly rather than calling an existing function @@ -1331,7 +1330,7 @@ lookupSyntaxName :: Name -- The standard name -> RnM (SyntaxExpr Name, FreeVars) -- Possibly a non-standard name lookupSyntaxName std_name = do { rebindable_on <- xoptM Opt_RebindableSyntax - ; if not rebindable_on then + ; if not rebindable_on then return (HsVar std_name, emptyFVs) else -- Get the similarly named thing from the local environment @@ -1342,21 +1341,20 @@ lookupSyntaxNames :: [Name] -- Standard names -> RnM ([HsExpr Name], FreeVars) -- See comments with HsExpr.ReboundNames lookupSyntaxNames std_names = do { rebindable_on <- xoptM Opt_RebindableSyntax - ; if not rebindable_on then + ; if not rebindable_on then return (map HsVar std_names, emptyFVs) else do { usr_names <- mapM (lookupOccRn . mkRdrUnqual . nameOccName) std_names ; return (map HsVar usr_names, mkFVs usr_names) } } -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Binding} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} newLocalBndrRn :: Located RdrName -> RnM Name -- Used for non-top-level binders. These should -- never be qualified. @@ -1496,16 +1494,15 @@ checkShadowedOccs (global_env,local_env) get_loc_occ ns ; return (gre_name gre `elemNameSet` fld_set) } | otherwise = do { sel_id <- tcLookupField (gre_name gre) ; return (isRecordSelector sel_id) } -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * What to do when a lookup fails -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} data WhereLooking = WL_Any -- Any binding | WL_Global -- Any top-level binding (local or imported) | WL_LocalTop -- Any top-level binding in this module @@ -1656,15 +1653,15 @@ unknownNameSuggestErr where_look tried_rdr_name quals_only _ LocalDef = [] quals_only occ (Imported is) = [ (mkRdrQual (is_as ispec) occ, Right ispec) | i <- is, let ispec = is_decl i, is_qual ispec ] -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Free variable manipulation} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} -- A useful utility addFvRn :: FreeVars -> RnM (thing, FreeVars) -> RnM (thing, FreeVars) addFvRn fvs1 thing_inside = do { (res, fvs2) <- thing_inside @@ -1689,16 +1686,15 @@ mapFvRnCPS _ [] cont = cont [] mapFvRnCPS f (x:xs) cont = f x $ \ x' -> mapFvRnCPS f xs $ \ xs' -> cont (x':xs') -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Envt utility functions} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} warnUnusedTopBinds :: [GlobalRdrElt] -> RnM () warnUnusedTopBinds gres = whenWOptM Opt_WarnUnusedBinds @@ -1765,9 +1761,7 @@ addUnusedWarning name span msg sep [msg <> colon, nest 2 $ pprNonVarNameSpace (occNameSpace (nameOccName name)) <+> quotes (ppr name)] -\end{code} -\begin{code} addNameClashErrRn :: RdrName -> [GlobalRdrElt] -> RnM () addNameClashErrRn rdr_name gres | all isLocalGRE gres -- If there are two or more *local* defns, we'll have reported @@ -1834,16 +1828,14 @@ checkTupSize tup_size = addErr (sep [ptext (sLit "A") <+> int tup_size <> ptext (sLit "-tuple is too large for GHC"), nest 2 (parens (ptext (sLit "max size is") <+> int mAX_TUPLE_SIZE)), nest 2 (ptext (sLit "Workaround: use nested tuples or define a data type"))]) -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Contexts for renaming errors} -%* * -%************************************************************************ - -\begin{code} +* * +************************************************************************ +-} data HsDocContext = TypeSigCtx SDoc @@ -1893,4 +1885,3 @@ docOfHsDocContext GHCiCtx = ptext (sLit "In GHCi input") docOfHsDocContext (SpliceTypeCtx hs_ty) = ptext (sLit "In the spliced type") <+> ppr hs_ty docOfHsDocContext ClassInstanceCtx = ptext (sLit "TcSplice.reifyInstances") docOfHsDocContext (VectDeclCtx tycon) = ptext (sLit "In the VECTORISE pragma for type constructor") <+> quotes (ppr tycon) -\end{code} diff --git a/compiler/rename/RnExpr.lhs b/compiler/rename/RnExpr.hs index 533cdcdef5..a0b5a1537c 100644 --- a/compiler/rename/RnExpr.lhs +++ b/compiler/rename/RnExpr.hs @@ -1,6 +1,6 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnExpr]{Renaming of expressions} Basically dependency analysis. @@ -8,8 +8,8 @@ Basically dependency analysis. Handles @Match@, @GRHSs@, @HsExpr@, and @Qualifier@ datatypes. In general, all of these functions return a renamed thing, and a set of free variables. +-} -\begin{code} {-# LANGUAGE CPP, ScopedTypeVariables #-} module RnExpr ( @@ -46,15 +46,15 @@ import SrcLoc import FastString import Control.Monad import TysWiredIn ( nilDataConName ) -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{Expressions} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnExprs :: [LHsExpr RdrName] -> RnM ([LHsExpr Name], FreeVars) rnExprs ls = rnExprs' ls emptyUniqSet where @@ -66,11 +66,9 @@ rnExprs ls = rnExprs' ls emptyUniqSet ; let acc' = acc `plusFV` fvExpr ; (exprs', fvExprs) <- acc' `seq` rnExprs' exprs acc' ; return (expr':exprs', fvExprs) } -\end{code} -Variables. We look up the variable and return the resulting name. +-- Variables. We look up the variable and return the resulting name. -\begin{code} rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars) rnLExpr = wrapLocFstM rnExpr @@ -294,26 +292,26 @@ rnExpr (ArithSeq _ _ seq) rnExpr (PArrSeq _ seq) = do { (new_seq, fvs) <- rnArithSeq seq ; return (PArrSeq noPostTcExpr new_seq, fvs) } -\end{code} +{- These three are pattern syntax appearing in expressions. Since all the symbols are reservedops we can simply reject them. We return a (bogus) EWildPat in each case. +-} -\begin{code} rnExpr EWildPat = return (hsHoleExpr, emptyFVs) rnExpr e@(EAsPat {}) = patSynErr e rnExpr e@(EViewPat {}) = patSynErr e rnExpr e@(ELazyPat {}) = patSynErr e -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * Arrow notation -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnExpr (HsProc pat body) = newArrowScope $ rnPat ProcExpr pat $ \ pat' -> do @@ -354,15 +352,15 @@ rnSection section@(SectionL expr op) ; return (SectionL expr' op', fvs_op `plusFV` fvs_expr) } rnSection other = pprPanic "rnSection" (ppr other) -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * Records -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnHsRecBinds :: HsRecFieldContext -> HsRecordBinds RdrName -> RnM (HsRecordBinds Name, FreeVars) rnHsRecBinds ctxt rec_binds@(HsRecFields { rec_dotdot = dd }) @@ -373,16 +371,15 @@ rnHsRecBinds ctxt rec_binds@(HsRecFields { rec_dotdot = dd }) where rn_field (L l fld) = do { (arg', fvs) <- rnLExpr (hsRecFieldArg fld) ; return (L l (fld { hsRecFieldArg = arg' }), fvs) } -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * Arrow commands -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnCmdArgs :: [LHsCmdTop RdrName] -> RnM ([LHsCmdTop Name], FreeVars) rnCmdArgs [] = return ([], emptyFVs) rnCmdArgs (arg:args) @@ -546,16 +543,15 @@ methodNamesStmt (ParStmt {}) = emptyFVs methodNamesStmt (TransStmt {}) = emptyFVs -- ParStmt and TransStmt can't occur in commands, but it's not convenient to error -- here so we just do what's convenient -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * Arithmetic sequences -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnArithSeq :: ArithSeqInfo RdrName -> RnM (ArithSeqInfo Name, FreeVars) rnArithSeq (From expr) = do { (expr', fvExpr) <- rnLExpr expr @@ -577,15 +573,15 @@ rnArithSeq (FromThenTo expr1 expr2 expr3) ; (expr3', fvExpr3) <- rnLExpr expr3 ; return (FromThenTo expr1' expr2' expr3', plusFVs [fvExpr1, fvExpr2, fvExpr3]) } -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{@Stmt@s: in @do@ expressions} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnStmts :: Outputable (body RdrName) => HsStmtContext Name -> (Located (body RdrName) -> RnM (Located (body Name), FreeVars)) -> [LStmt RdrName (Located (body RdrName))] @@ -791,8 +787,8 @@ lookupStmtName ctxt n where rebindable = lookupSyntaxName n not_rebindable = return (HsVar n, emptyFVs) -\end{code} +{- Note [Renaming parallel Stmts] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Renaming parallel statements is painful. Given, say @@ -811,13 +807,13 @@ To satisfy (a) we nest the segements. To satisfy (b) we check for duplicates just before thing_inside. To satisfy (c) we reset the LocalRdrEnv each time. -%************************************************************************ -%* * +************************************************************************ +* * \subsubsection{mdo expressions} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} type FwdRefs = NameSet type Segment stmts = (Defs, Uses, -- May include defs @@ -986,7 +982,7 @@ rn_rec_stmts rnBody bndrs stmts ; return (concat segs_s) } --------------------------------------------- -segmentRecStmts :: HsStmtContext Name +segmentRecStmts :: HsStmtContext Name -> Stmt Name body -> [Segment (LStmt Name body)] -> FreeVars -> ([LStmt Name body], FreeVars) @@ -1039,8 +1035,8 @@ addFwdRefs segs all_defs = later_defs `unionNameSet` defs new_fwds = fwds `unionNameSet` (uses `intersectNameSet` later_defs) -- Add the downstream fwd refs here -\end{code} +{- Note [Segmenting mdo] ~~~~~~~~~~~~~~~~~~~~~ NB. June 7 2012: We only glom segments that appear in an explicit mdo; @@ -1082,8 +1078,8 @@ glom it together with the first two groups { rec { x <- ...y...; p <- z ; y <- ...x... ; q <- x ; z <- y } ; r <- x } +-} -\begin{code} glomSegments :: HsStmtContext Name -> [Segment (LStmt Name body)] -> [Segment [LStmt Name body]] -- See Note [Glomming segments] @@ -1132,15 +1128,15 @@ segsToStmts empty_rec_stmt ((defs, uses, fwds, ss) : segs) fvs_later non_rec = isSingleton ss && isEmptyNameSet fwds used_later = defs `intersectNameSet` later_uses -- The ones needed after the RecStmt -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{Errors} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} checkEmptyStmts :: HsStmtContext Name -> RnM () -- We've seen an empty sequence of Stmts... is that ok? checkEmptyStmts ctxt @@ -1309,4 +1305,3 @@ badIpBinds :: Outputable a => SDoc -> a -> SDoc badIpBinds what binds = hang (ptext (sLit "Implicit-parameter bindings illegal in") <+> what) 2 (ppr binds) -\end{code} diff --git a/compiler/rename/RnExpr.lhs-boot b/compiler/rename/RnExpr.hs-boot index 0a00a9e2bc..5419870d38 100644 --- a/compiler/rename/RnExpr.lhs-boot +++ b/compiler/rename/RnExpr.hs-boot @@ -1,4 +1,3 @@ -\begin{code} module RnExpr where import HsSyn import Name ( Name ) @@ -12,10 +11,8 @@ rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars) rnStmts :: --forall thing body. - Outputable (body RdrName) => HsStmtContext Name + Outputable (body RdrName) => HsStmtContext Name -> (Located (body RdrName) -> RnM (Located (body Name), FreeVars)) -> [LStmt RdrName (Located (body RdrName))] -> ([Name] -> RnM (thing, FreeVars)) - -> RnM (([LStmt Name (Located (body Name))], thing), FreeVars) -\end{code} - + -> RnM (([LStmt Name (Located (body Name))], thing), FreeVars) diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.hs index 02a45d0db8..bff2ed0f29 100644 --- a/compiler/rename/RnNames.lhs +++ b/compiler/rename/RnNames.hs @@ -1,9 +1,9 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnNames]{Extracting imported and top-level names in scope} +-} -\begin{code} {-# LANGUAGE CPP, NondecreasingIndentation #-} module RnNames ( @@ -48,14 +48,13 @@ import Data.List ( partition, (\\), find ) import qualified Data.Set as Set import System.FilePath ((</>)) import System.IO -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{rnImports} -%* * -%************************************************************************ +* * +************************************************************************ Note [Tracking Trust Transitively] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -135,9 +134,8 @@ compilation errors in code that doesn't do anything with Safe Haskell simply because they are using the network package. They will have to call 'ghc-pkg trust network' to get everything working. Due to this invasive nature of going with yes we have gone with no for now. +-} - -\begin{code} -- | Process Import Decls -- Do the non SOURCE ones first, so that we get a helpful warning for SOURCE -- ones that are unnecessary @@ -357,14 +355,13 @@ warnRedundantSourceImport :: ModuleName -> SDoc warnRedundantSourceImport mod_name = ptext (sLit "Unnecessary {-# SOURCE #-} in the import of module") <+> quotes (ppr mod_name) -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{importsFromLocalDecls} -%* * -%************************************************************************ +* * +************************************************************************ From the top-level declarations of this module produce * the lexical environment @@ -411,8 +408,8 @@ top level binders specially in two ways stage. This is a slight hack, because the stage field was really meant for the type checker, and here we are not interested in the fields of Brack, hence the error thunks in thRnBrack. +-} -\begin{code} extendGlobalRdrEnvRn :: [AvailInfo] -> MiniFixityEnv -> RnM (TcGblEnv, TcLclEnv) @@ -473,14 +470,14 @@ extendGlobalRdrEnvRn avails new_fixities = fix_env where occ = nameOccName name -\end{code} +{- @getLocalDeclBinders@ returns the names for an @HsDecl@. It's used for source code. *** See "THE NAMING STORY" in HsDecls **** +-} -\begin{code} getLocalNonValBinders :: MiniFixityEnv -> HsGroup RdrName -> RnM ((TcGblEnv, TcLclEnv), NameSet) -- Get all the top-level binders bound the group *except* @@ -568,8 +565,8 @@ getLocalNonValBinders fixity_env ; sub_names <- mapM newTopSrcBinder (hsDataFamInstBinders ti_decl) ; return (AvailTC (unLoc main_name) sub_names) } -- main_name is not bound here! -\end{code} +{- Note [Looking up family names in family instances] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider @@ -588,21 +585,21 @@ Solution is simple: process the type family declarations first, extend the environment, and then process the type instances. -%************************************************************************ -%* * +************************************************************************ +* * \subsection{Filtering imports} -%* * -%************************************************************************ +* * +************************************************************************ @filterImports@ takes the @ExportEnv@ telling what the imported module makes available, and filters it through the import spec (if any). Note [Dealing with imports] ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -For import M( ies ), we take the mi_exports of M, and make - imp_occ_env :: OccEnv (Name, AvailInfo, Maybe Name) +For import M( ies ), we take the mi_exports of M, and make + imp_occ_env :: OccEnv (Name, AvailInfo, Maybe Name) One entry for each Name that M exports; the AvailInfo describes just -that Name. +that Name. The situation is made more complicated by associated types. E.g. module M where @@ -619,8 +616,8 @@ From this we construct the imp_occ_env Note that the imp_occ_env will have entries for data constructors too, although we never look up data constructors. +-} -\begin{code} filterImports :: [ModIface] -> ImpDeclSpec -- The span for the entire import decl @@ -756,7 +753,7 @@ filterImports ifaces decl_spec (Just (want_hiding, L l import_items)) (name, AvailTC _ ns, mb_parent) <- lookup_name rdr_tc -- Look up the children in the sub-names of the parent - let subnames = case ns of -- The tc is first in ns, + let subnames = case ns of -- The tc is first in ns, [] -> [] -- if it is there at all -- See the AvailTC Invariant in Avail.hs (n1:ns1) | n1 == name -> ns1 @@ -814,15 +811,15 @@ catchIELookup m h = case m of catIELookupM :: [IELookupM a] -> [a] catIELookupM ms = [ a | Succeeded a <- ms ] -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Import/Export Utils} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} greExportAvail :: GlobalRdrElt -> AvailInfo greExportAvail gre = case gre_par gre of @@ -914,14 +911,13 @@ nubAvails :: [AvailInfo] -> [AvailInfo] nubAvails avails = nameEnvElts (foldl add emptyNameEnv avails) where add env avail = extendNameEnv_C plusAvail env (availName avail) avail -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsection{Export list processing} -%* * -%************************************************************************ +* * +************************************************************************ Processing the export list. @@ -961,8 +957,8 @@ At one point I implemented a compromise: But the compromise seemed too much of a hack, so we backed it out. You just have to use an explicit export list: module M( F(..) ) where ... +-} -\begin{code} type ExportAccum -- The type of the accumulating parameter of -- the main worker function in rnExports = ([LIE Name], -- Export items with Names @@ -1262,16 +1258,15 @@ dupExport_ok n ie1 ie2 single (IEVar {}) = True single (IEThingAbs {}) = True single _ = False -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Unused names} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} reportUnusedNames :: Maybe (Located [LIE RdrName]) -- Export list -> TcGblEnv -> RnM () reportUnusedNames _export_decls gbl_env @@ -1313,26 +1308,24 @@ reportUnusedNames _export_decls gbl_env unused_locals = filter is_unused_local defined_but_not_used is_unused_local :: GlobalRdrElt -> Bool is_unused_local gre = isLocalGRE gre && isExternalName (gre_name gre) -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Unused imports} -%* * -%********************************************************* +* * +********************************************************* This code finds which import declarations are unused. The specification and implementation notes are here: http://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/UnusedImports +-} -\begin{code} type ImportDeclUsage = ( LImportDecl Name -- The import declaration , [AvailInfo] -- What *is* used (normalised) , [Name] ) -- What is imported but *not* used -\end{code} -\begin{code} warnUnusedImportDecls :: TcGblEnv -> RnM () warnUnusedImportDecls gbl_env = do { uses <- readMutVar (tcg_used_rdrnames gbl_env) @@ -1352,9 +1345,8 @@ warnUnusedImportDecls gbl_env ; whenGOptM Opt_D_dump_minimal_imports $ printMinimalImports usage } -\end{code} - +{- Note [The ImportMap] ~~~~~~~~~~~~~~~~~~~~ The ImportMap is a short-lived intermediate data struture records, for @@ -1374,8 +1366,8 @@ It's just a cheap hack; we could equally well use the Span too. The AvailInfos are the things imported from that decl (just a list, not normalised). +-} -\begin{code} type ImportMap = Map SrcLoc [AvailInfo] -- See [The ImportMap] findImportUsage :: [LImportDecl Name] @@ -1462,9 +1454,7 @@ extendImportMap rdr_env rdr imp_map isImpAll :: ImportSpec -> Bool isImpAll (ImpSpec { is_item = ImpAll }) = True isImpAll _other = False -\end{code} -\begin{code} warnUnusedImport :: ImportDeclUsage -> RnM () warnUnusedImport (L loc decl, used, unused) | Just (False,L _ []) <- ideclHiding decl @@ -1491,8 +1481,8 @@ warnUnusedImport (L loc decl, used, unused) | otherwise = Outputable.empty pp_mod = ppr (unLoc (ideclName decl)) pp_not_used = text "is redundant" -\end{code} +{- Note [Do not warn about Prelude hiding] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We do not warn about @@ -1513,8 +1503,8 @@ decls, and simply trim their import lists. NB that * We do not disard a decl altogether; we might need instances from it. Instead we just trim to an empty import list +-} -\begin{code} printMinimalImports :: [ImportDeclUsage] -> RnM () -- See Note [Printing minimal imports] printMinimalImports imports_w_usage @@ -1571,8 +1561,8 @@ printMinimalImports imports_w_usage _other -> map (IEVar . noLoc) ns where all_used avail_occs = all (`elem` ns) avail_occs -\end{code} +{- Note [Partial export] ~~~~~~~~~~~~~~~~~~~~~ Suppose we have @@ -1593,13 +1583,13 @@ which we would usually generate if C was exported from B. Hence the (x `elem` xs) test when deciding what to generate. -%************************************************************************ -%* * +************************************************************************ +* * \subsection{Errors} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} qualImportItemErr :: RdrName -> SDoc qualImportItemErr rdr = hang (ptext (sLit "Illegal qualified name in import item:")) @@ -1789,4 +1779,3 @@ checkConName name = checkErr (isRdrDataCon name) (badDataCon name) badDataCon :: RdrName -> SDoc badDataCon name = hsep [ptext (sLit "Illegal data constructor name"), quotes (ppr name)] -\end{code} diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.hs index 90002d8b7e..160f9ad2d1 100644 --- a/compiler/rename/RnPat.lhs +++ b/compiler/rename/RnPat.hs @@ -1,6 +1,6 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnPat]{Renaming of patterns} Basically dependency analysis. @@ -8,8 +8,8 @@ Basically dependency analysis. Handles @Match@, @GRHSs@, @HsExpr@, and @Qualifier@ datatypes. In general, all of these functions return a renamed thing, and a set of free variables. +-} -\begin{code} {-# LANGUAGE CPP, RankNTypes, ScopedTypeVariables #-} module RnPat (-- main entry points @@ -40,7 +40,7 @@ import {-# SOURCE #-} TcSplice ( runQuasiQuotePat ) #include "HsVersions.h" -import HsSyn +import HsSyn import TcRnMonad import TcHsSyn ( hsOverLitName ) import RnEnv @@ -65,14 +65,13 @@ import TysWiredIn ( nilDataCon ) import DataCon ( dataConName ) import Control.Monad ( when, liftM, ap ) import Data.Ratio -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * The CpsRn Monad -%* * -%********************************************************* +* * +********************************************************* Note [CpsRn monad] ~~~~~~~~~~~~~~~~~~ @@ -85,17 +84,17 @@ style of programming: where rs::[RdrName], ns::[Name] -The idea is that '...blah...' +The idea is that '...blah...' a) sees the bindings of ns b) returns the free variables it mentions so that bindNames can report unused ones -In particular, +In particular, mapM rnPatAndThen [p1, p2, p3] -has a *left-to-right* scoping: it makes the binders in +has a *left-to-right* scoping: it makes the binders in p1 scope over p2,p3. +-} -\begin{code} newtype CpsRn b = CpsRn { unCpsRn :: forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars) } -- See Note [CpsRn monad] @@ -125,19 +124,19 @@ liftCpsFV rn_thing = CpsRn (\k -> do { (v,fvs1) <- rn_thing wrapSrcSpanCps :: (a -> CpsRn b) -> Located a -> CpsRn (Located b) -- Set the location, and also wrap it around the value returned wrapSrcSpanCps fn (L loc a) - = CpsRn (\k -> setSrcSpan loc $ - unCpsRn (fn a) $ \v -> + = CpsRn (\k -> setSrcSpan loc $ + unCpsRn (fn a) $ \v -> k (L loc v)) lookupConCps :: Located RdrName -> CpsRn (Located Name) -lookupConCps con_rdr +lookupConCps con_rdr = CpsRn (\k -> do { con_name <- lookupLocatedOccRn con_rdr ; (r, fvs) <- k con_name ; return (r, addOneFV fvs (unLoc con_name)) }) -- We add the constructor name to the free vars -- See Note [Patterns are uses] -\end{code} +{- Note [Patterns are uses] ~~~~~~~~~~~~~~~~~~~~~~~~ Consider @@ -165,20 +164,20 @@ where we don't know yet whether P2 is a constructor or a pattern synonym. So for now, we do report conid occurrences in patterns as uses. -%********************************************************* -%* * +********************************************************* +* * Name makers -%* * -%********************************************************* +* * +********************************************************* Externally abstract type of name makers, which is how you go from a RdrName to a Name +-} -\begin{code} -data NameMaker - = LamMk -- Lambdas +data NameMaker + = LamMk -- Lambdas Bool -- True <=> report unused bindings - -- (even if True, the warning only comes out + -- (even if True, the warning only comes out -- if -fwarn-unused-matches is on) | LetMk -- Let bindings, incl top level @@ -194,7 +193,7 @@ isTopRecNameMaker (LetMk TopLevel _) = True isTopRecNameMaker _ = False localRecNameMaker :: MiniFixityEnv -> NameMaker -localRecNameMaker fix_env = LetMk NotTopLevel fix_env +localRecNameMaker fix_env = LetMk NotTopLevel fix_env matchNameMaker :: HsMatchContext a -> NameMaker matchNameMaker ctxt = LamMk report_unused @@ -210,19 +209,19 @@ matchNameMaker ctxt = LamMk report_unused rnHsSigCps :: HsWithBndrs RdrName (LHsType RdrName) -> CpsRn (HsWithBndrs Name (LHsType Name)) -rnHsSigCps sig +rnHsSigCps sig = CpsRn (rnHsBndrSig PatCtx sig) newPatName :: NameMaker -> Located RdrName -> CpsRn Name newPatName (LamMk report_unused) rdr_name - = CpsRn (\ thing_inside -> + = CpsRn (\ thing_inside -> do { name <- newLocalBndrRn rdr_name ; (res, fvs) <- bindLocalNames [name] (thing_inside name) ; when report_unused $ warnUnusedMatches [name] fvs ; return (res, name `delFV` fvs) }) newPatName (LetMk is_top fix_env) rdr_name - = CpsRn (\ thing_inside -> + = CpsRn (\ thing_inside -> do { name <- case is_top of NotTopLevel -> newLocalBndrRn rdr_name TopLevel -> newTopSrcBinder rdr_name @@ -230,15 +229,15 @@ newPatName (LetMk is_top fix_env) rdr_name -- See Note [View pattern usage] addLocalFixities fix_env [name] $ thing_inside name }) - + -- Note: the bindLocalNames is somewhat suspicious -- because it binds a top-level name as a local name. -- however, this binding seems to work, and it only exists for -- the duration of the patterns and the continuation; -- then the top-level name is added to the global env -- before going on to the RHSes (see RnSource.lhs). -\end{code} +{- Note [View pattern usage] ~~~~~~~~~~~~~~~~~~~~~~~~~ Consider @@ -248,28 +247,28 @@ We want to "see" this use, and in let-bindings we collect all uses and report unused variables at the binding level. So we must use bindLocalNames here, *not* bindLocalNameFV. Trac #3943. -%********************************************************* -%* * +********************************************************* +* * External entry points -%* * -%********************************************************* +* * +********************************************************* There are various entry points to renaming patterns, depending on (1) whether the names created should be top-level names or local names (2) whether the scope of the names is entirely given in a continuation (e.g., in a case or lambda, but not in a let or at the top-level, because of the way mutually recursive bindings are handled) - (3) whether the a type signature in the pattern can bind - lexically-scoped type variables (for unpacking existential + (3) whether the a type signature in the pattern can bind + lexically-scoped type variables (for unpacking existential type vars in data constructors) (4) whether we do duplicate and unused variable checking (5) whether there are fixity declarations associated with the names bound by the patterns that need to be brought into scope with them. - + Rather than burdening the clients of this module with all of these choices, we export the three points in this design space that we actually need: +-} -\begin{code} -- ----------- Entry point 1: rnPats ------------------- -- Binds local names; the scope of the bindings is entirely in the thing_inside -- * allows type sigs to bind type vars @@ -277,7 +276,7 @@ There are various entry points to renaming patterns, depending on -- * unused and duplicate checking -- * no fixities rnPats :: HsMatchContext Name -- for error messages - -> [LPat RdrName] + -> [LPat RdrName] -> ([LPat Name] -> RnM (a, FreeVars)) -> RnM (a, FreeVars) rnPats ctxt pats thing_inside @@ -286,14 +285,14 @@ rnPats ctxt pats thing_inside -- (1) rename the patterns, bringing into scope all of the term variables -- (2) then do the thing inside. ; unCpsRn (rnLPatsAndThen (matchNameMaker ctxt) pats) $ \ pats' -> do - { -- Check for duplicated and shadowed names + { -- Check for duplicated and shadowed names -- Must do this *after* renaming the patterns -- See Note [Collect binders only after renaming] in HsUtils -- Because we don't bind the vars all at once, we can't - -- check incrementally for duplicates; + -- check incrementally for duplicates; -- Nor can we check incrementally for shadowing, else we'll -- complain *twice* about duplicates e.g. f (x,x) = ... - ; addErrCtxt doc_pat $ + ; addErrCtxt doc_pat $ checkDupAndShadowedNames envs_before $ collectPatsBinders pats' ; thing_inside pats' } } @@ -301,11 +300,11 @@ rnPats ctxt pats thing_inside doc_pat = ptext (sLit "In") <+> pprMatchContext ctxt rnPat :: HsMatchContext Name -- for error messages - -> LPat RdrName + -> LPat RdrName -> (LPat Name -> RnM (a, FreeVars)) - -> RnM (a, FreeVars) -- Variables bound by pattern do not - -- appear in the result FreeVars -rnPat ctxt pat thing_inside + -> RnM (a, FreeVars) -- Variables bound by pattern do not + -- appear in the result FreeVars +rnPat ctxt pat thing_inside = rnPats ctxt [pat] (\pats' -> let [pat'] = pats' in thing_inside pat') applyNameMaker :: NameMaker -> Located RdrName -> RnM Name @@ -322,19 +321,18 @@ rnBindPat :: NameMaker -> LPat RdrName -> RnM (LPat Name, FreeVars) -- Returned FreeVars are the free variables of the pattern, - -- of course excluding variables bound by this pattern + -- of course excluding variables bound by this pattern rnBindPat name_maker pat = runCps (rnLPatAndThen name_maker pat) -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * The main event -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} -- ----------- Entry point 3: rnLPatAndThen ------------------- -- General version: parametrized by how you make new names @@ -358,7 +356,7 @@ rnPatAndThen mk (VarPat rdr) = do { loc <- liftCps getSrcSpanM ; return (VarPat name) } -- we need to bind pattern variables for view pattern expressions -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple) - + rnPatAndThen mk (SigPatIn pat sig) -- When renaming a pattern type signature (e.g. f (a :: T) = ...), it is -- important to rename its type signature _before_ renaming the rest of the @@ -372,11 +370,11 @@ rnPatAndThen mk (SigPatIn pat sig) = do { sig' <- rnHsSigCps sig ; pat' <- rnLPatAndThen mk pat ; return (SigPatIn pat' sig') } - + rnPatAndThen mk (LitPat lit) | HsString src s <- lit = do { ovlStr <- liftCps (xoptM Opt_OverloadedStrings) - ; if ovlStr + ; if ovlStr then rnPatAndThen mk (mkNPat (mkHsIsString src s placeHolderType) Nothing) else normal_lit } @@ -410,8 +408,8 @@ rnPatAndThen mk p@(ViewPat expr pat _ty) = do { liftCps $ do { vp_flag <- xoptM Opt_ViewPatterns ; checkErr vp_flag (badViewPat p) } -- Because of the way we're arranging the recursive calls, - -- this will be in the right context - ; expr' <- liftCpsFV $ rnLExpr expr + -- this will be in the right context + ; expr' <- liftCpsFV $ rnLExpr expr ; pat' <- rnLPatAndThen mk pat -- Note: at this point the PreTcType in ty can only be a placeHolder -- ; return (ViewPat expr' pat' ty) } @@ -423,7 +421,7 @@ rnPatAndThen mk (ConPatIn con stuff) = case unLoc con == nameRdrName (dataConName nilDataCon) of True -> do { ol_flag <- liftCps $ xoptM Opt_OverloadedLists ; if ol_flag then rnPatAndThen mk (ListPat [] placeHolderType Nothing) - else rnConPatAndThen mk con stuff} + else rnConPatAndThen mk con stuff} False -> rnConPatAndThen mk con stuff rnPatAndThen mk (ListPat pats _ _) @@ -448,12 +446,12 @@ rnPatAndThen mk (SplicePat splice) = do { eith <- liftCpsFV $ rnSplicePat splice ; case eith of -- See Note [rnSplicePat] in RnSplice Left not_yet_renamed -> rnPatAndThen mk not_yet_renamed - Right already_renamed -> return already_renamed } - + Right already_renamed -> return already_renamed } + rnPatAndThen mk (QuasiQuotePat qq) = do { pat <- liftCps $ runQuasiQuotePat qq -- Wrap the result of the quasi-quoter in parens so that we don't - -- lose the outermost location set by runQuasiQuote (#7918) + -- lose the outermost location set by runQuasiQuote (#7918) ; rnPatAndThen mk (ParPat pat) } rnPatAndThen _ pat = pprPanic "rnLPatAndThen" (ppr pat) @@ -462,7 +460,7 @@ rnPatAndThen _ pat = pprPanic "rnLPatAndThen" (ppr pat) -------------------- rnConPatAndThen :: NameMaker -> Located RdrName -- the constructor - -> HsConPatDetails RdrName + -> HsConPatDetails RdrName -> CpsRn (Pat Name) rnConPatAndThen mk con (PrefixCon pats) @@ -491,7 +489,7 @@ rnHsRecPatsAndThen mk (L _ con) hs_rec_fields@(HsRecFields { rec_dotdot = dd }) = do { flds <- liftCpsFV $ rnHsRecFields (HsRecFieldPat con) VarPat hs_rec_fields ; flds' <- mapM rn_field (flds `zip` [1..]) ; return (HsRecFields { rec_flds = flds', rec_dotdot = dd }) } - where + where rn_field (L l fld, n') = do { arg' <- rnLPatAndThen (nested_mk dd mk n') (hsRecFieldArg fld) ; return (L l (fld { hsRecFieldArg = arg' })) } @@ -500,23 +498,22 @@ rnHsRecPatsAndThen mk (L _ con) hs_rec_fields@(HsRecFields { rec_dotdot = dd }) nested_mk Nothing mk _ = mk nested_mk (Just _) mk@(LetMk {}) _ = mk nested_mk (Just n) (LamMk report_unused) n' = LamMk (report_unused && (n' <= n)) -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * Record fields -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} -data HsRecFieldContext +data HsRecFieldContext = HsRecFieldCon Name | HsRecFieldPat Name | HsRecFieldUpd rnHsRecFields - :: forall arg. + :: forall arg. HsRecFieldContext -> (RdrName -> arg) -- When punning, use this to build a new field -> HsRecFields RdrName (Located arg) @@ -552,9 +549,9 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) HsRecFieldCon con | not (isUnboundName con) -> Just con HsRecFieldPat con | not (isUnboundName con) -> Just con _ {- update or isUnboundName con -} -> Nothing - -- The unbound name test is because if the constructor + -- The unbound name test is because if the constructor -- isn't in scope the constructor lookup will add an error - -- add an error, but still return an unbound name. + -- add an error, but still return an unbound name. -- We don't want that to screw up the dot-dot fill-in stuff. doc = case mb_con of @@ -565,7 +562,7 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) , hsRecFieldArg = arg , hsRecPun = pun })) = do { fld'@(L loc fld_nm) <- wrapLocM (lookupSubBndrOcc True parent doc) fld - ; arg' <- if pun + ; arg' <- if pun then do { checkErr pun_ok (badPun fld) ; return (L loc (mk_arg (mkRdrUnqual (nameOccName fld_nm)))) } else return arg @@ -601,7 +598,7 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) -- ignoring the record field itself -- Eg. data R = R { x,y :: Int } -- f x = R { .. } -- Should expand to R {x=x}, not R{x=x,y=y} - arg_in_scope fld + arg_in_scope fld = rdr `elemLocalRdrEnv` lcl_env || notNull [ gre | gre <- lookupGRE_RdrName rdr rdr_env , case gre_par gre of @@ -617,7 +614,7 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) , not (null gres) -- Check field is in scope , case ctxt of HsRecFieldCon {} -> arg_in_scope fld - _other -> True ] + _other -> True ] ; addUsedRdrNames (map greRdrName dot_dot_gres) ; return [ L loc (HsRecField @@ -629,17 +626,17 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) arg_rdr = mkRdrUnqual (nameOccName fld) ] } check_disambiguation :: Bool -> Maybe Name -> RnM Parent - -- When disambiguation is on, + -- When disambiguation is on, check_disambiguation disambig_ok mb_con | disambig_ok, Just con <- mb_con = do { env <- getGlobalRdrEnv; return (ParentIs (find_tycon env con)) } | otherwise = return NoParent - + find_tycon :: GlobalRdrEnv -> Name {- DataCon -} -> Name {- TyCon -} -- Return the parent *type constructor* of the data constructor - -- That is, the parent of the data constructor. + -- That is, the parent of the data constructor. -- That's the parent to use for looking up record fields. - find_tycon env con + find_tycon env con | Just (AConLike (RealDataCon dc)) <- wiredInNameTyThing_maybe con = tyConName (dataConTyCon dc) -- Special case for [], which is built-in syntax -- and not in the GlobalRdrEnv (Trac #8448) @@ -679,7 +676,7 @@ badPun fld = vcat [ptext (sLit "Illegal use of punning for field") <+> quotes (p dupFieldErr :: HsRecFieldContext -> [RdrName] -> SDoc dupFieldErr ctxt dups - = hsep [ptext (sLit "duplicate field name"), + = hsep [ptext (sLit "duplicate field name"), quotes (ppr (head dups)), ptext (sLit "in record"), pprRFC ctxt] @@ -687,20 +684,19 @@ pprRFC :: HsRecFieldContext -> SDoc pprRFC (HsRecFieldCon {}) = ptext (sLit "construction") pprRFC (HsRecFieldPat {}) = ptext (sLit "pattern") pprRFC (HsRecFieldUpd {}) = ptext (sLit "update") -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{Literals} -%* * -%************************************************************************ +* * +************************************************************************ When literals occur we have to make sure that the types and classes they involve are made available. +-} -\begin{code} rnLit :: HsLit -> RnM () rnLit (HsChar _ c) = checkErr (inCharRange c) (bogusCharError c) rnLit _ = return () @@ -727,15 +723,15 @@ rnOverLit origLit ; return (lit { ol_witness = from_thing_name , ol_rebindable = rebindable , ol_type = placeHolderType }, fvs) } -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * \subsubsection{Errors} -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} patSigErr :: Outputable a => a -> SDoc patSigErr ty = (ptext (sLit "Illegal signature in pattern:") <+> ppr ty) @@ -748,4 +744,3 @@ bogusCharError c badViewPat :: Pat RdrName -> SDoc badViewPat pat = vcat [ptext (sLit "Illegal view pattern: ") <+> ppr pat, ptext (sLit "Use ViewPatterns to enable view patterns")] -\end{code} diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.hs index f99bc810d5..95211cbdfc 100644 --- a/compiler/rename/RnSource.lhs +++ b/compiler/rename/RnSource.hs @@ -1,9 +1,9 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnSource]{Main pass of renamer} +-} -\begin{code} {-# LANGUAGE CPP, ScopedTypeVariables #-} module RnSource ( @@ -52,8 +52,8 @@ import Data.List( partition, sortBy ) import Data.Traversable (traverse) #endif import Maybes( orElse, mapMaybe ) -\end{code} +{- @rnSourceDecl@ `renames' declarations. It simultaneously performs dependency analysis and precedence parsing. It also does the following error checks: @@ -68,9 +68,8 @@ Checks that all variable occurrences are defined. \item Checks the @(..)@ etc constraints in the export list. \end{enumerate} +-} - -\begin{code} -- Brings the binders of the group into scope in the appropriate places; -- does NOT assume that anything is in scope already rnSrcDecls :: [Name] -> HsGroup RdrName -> RnM (TcGblEnv, HsGroup Name) @@ -221,16 +220,15 @@ addTcgDUs tcg_env dus = tcg_env { tcg_dus = tcg_dus tcg_env `plusDU` dus } rnList :: (a -> RnM (b, FreeVars)) -> [Located a] -> RnM ([Located b], FreeVars) rnList f xs = mapFvRn (wrapLocFstM f) xs -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * HsDoc stuff -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnDocDecl :: DocDecl -> RnM DocDecl rnDocDecl (DocCommentNext doc) = do rn_doc <- rnHsDoc doc @@ -244,16 +242,15 @@ rnDocDecl (DocCommentNamed str doc) = do rnDocDecl (DocGroup lev doc) = do rn_doc <- rnHsDoc doc return (DocGroup lev rn_doc) -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * Source-code fixity declarations -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnSrcFixityDecls :: NameSet -> [LFixitySig RdrName] -> RnM [LFixitySig Name] -- Rename the fixity decls, so we can put -- the renamed decls in the renamed syntax tree @@ -285,22 +282,21 @@ rnSrcFixityDecls bndr_set fix_decls do names <- lookupLocalTcNames sig_ctxt what rdr_name return [ L name_loc name | name <- names ] what = ptext (sLit "fixity signature") -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * Source-code deprecations declarations -%* * -%********************************************************* +* * +********************************************************* Check that the deprecated names are defined, are defined locally, and that there are no duplicate deprecations. It's only imported deprecations, dealt with in RnIfaces, that we gather them together. +-} -\begin{code} -- checks that the deprecations are defined locally, and that there are no duplicates rnSrcWarnDecls :: NameSet -> [LWarnDecl RdrName] -> RnM Warnings rnSrcWarnDecls _ [] @@ -339,15 +335,14 @@ dupWarnDecl (L loc _) rdr_name = vcat [ptext (sLit "Multiple warning declarations for") <+> quotes (ppr rdr_name), ptext (sLit "also at ") <+> ppr loc] -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Annotation declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnAnnDecl :: AnnDecl RdrName -> RnM (AnnDecl Name, FreeVars) rnAnnDecl ann@(HsAnnotation provenance expr) = addErrCtxt (annCtxt ann) $ @@ -360,30 +355,30 @@ rnAnnProvenance :: AnnProvenance RdrName -> RnM (AnnProvenance Name, FreeVars) rnAnnProvenance provenance = do provenance' <- traverse lookupTopBndrRn provenance return (provenance', maybe emptyFVs unitFV (annProvenanceName_maybe provenance')) -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Default declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnDefaultDecl :: DefaultDecl RdrName -> RnM (DefaultDecl Name, FreeVars) rnDefaultDecl (DefaultDecl tys) = do { (tys', fvs) <- rnLHsTypes doc_str tys ; return (DefaultDecl tys', fvs) } where doc_str = DefaultDeclCtx -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Foreign declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnHsForeignDecl :: ForeignDecl RdrName -> RnM (ForeignDecl Name, FreeVars) rnHsForeignDecl (ForeignImport name ty _ spec) = do { topEnv :: HscEnv <- getTopEnv @@ -425,17 +420,14 @@ patchCCallTarget packageKey callTarget = StaticTarget label Nothing isFun -> StaticTarget label (Just packageKey) isFun _ -> callTarget - -\end{code} - - -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Instance declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnSrcInstDecl :: InstDecl RdrName -> RnM (InstDecl Name, FreeVars) rnSrcInstDecl (TyFamInstD { tfid_inst = tfi }) = do { (tfi', fvs) <- rnTyFamInstDecl Nothing tfi @@ -612,11 +604,9 @@ rnDataFamInstDecl mb_cls (DataFamInstDecl { dfid_tycon = tycon , dfid_pats = pats' , dfid_defn = defn' , dfid_fvs = fvs }, fvs) } -\end{code} -Renaming of the associated types in instances. +-- Renaming of the associated types in instances. -\begin{code} -- Rename associated type family decl in class rnATDecls :: Name -- Class -> [LFamilyDecl RdrName] @@ -641,8 +631,8 @@ rnATInstDecls rnFun cls hs_tvs at_insts where tv_ns = hsLKiTyVarNames hs_tvs -- See Note [Renaming associated types] -\end{code} +{- Note [Renaming associated types] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check that the RHS of the decl mentions only type variables @@ -669,9 +659,8 @@ can all be in scope (Trac #5862): id :: Ob x a => x a a (.) :: (Ob x a, Ob x b, Ob x c) => x b c -> x a b -> x a c Here 'k' is in scope in the kind signature, just like 'x'. +-} - -\begin{code} extendTyVarEnvForMethodBinds :: [Name] -> RnM (LHsBinds Name, FreeVars) -> RnM (LHsBinds Name, FreeVars) @@ -684,15 +673,15 @@ extendTyVarEnvForMethodBinds ktv_names thing_inside extendTyVarEnvFVRn ktv_names thing_inside else thing_inside } -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Stand-alone deriving declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnSrcDerivDecl :: DerivDecl RdrName -> RnM (DerivDecl Name, FreeVars) rnSrcDerivDecl (DerivDecl ty overlap) = do { standalone_deriv_ok <- xoptM Opt_StandaloneDeriving @@ -704,15 +693,15 @@ standaloneDerivErr :: SDoc standaloneDerivErr = hang (ptext (sLit "Illegal standalone deriving declaration")) 2 (ptext (sLit "Use StandaloneDeriving to enable this extension")) -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Rules} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnHsRuleDecl :: RuleDecl RdrName -> RnM (RuleDecl Name, FreeVars) rnHsRuleDecl (HsRule rule_name act vars lhs _fv_lhs rhs _fv_rhs) = do { let rdr_names_w_loc = map get_var vars @@ -749,8 +738,8 @@ bindHsRuleVars rule_name vars names thing_inside go [] [] thing_inside = thing_inside [] go vars names _ = pprPanic "bindRuleVars" (ppr vars $$ ppr names) -\end{code} +{- Note [Rule LHS validity checking] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check the shape of a transformation rule LHS. Currently we only allow @@ -764,8 +753,8 @@ with LHSs with a complicated desugaring (and hence unlikely to match); But there are legitimate non-trivial args ei, like sections and lambdas. So it seems simmpler not to check at all, and that is why check_e is commented out. +-} -\begin{code} checkValidRule :: FastString -> [Name] -> LHsExpr Name -> NameSet -> RnM () checkValidRule rule_name ids lhs' fv_lhs' = do { -- Check for the form of the LHS @@ -821,16 +810,15 @@ badRuleLhsErr name lhs bad_e ptext (sLit "in left-hand side:") <+> ppr lhs])] $$ ptext (sLit "LHS must be of form (f e1 .. en) where f is not forall'd") -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Vectorisation declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnHsVectDecl :: VectDecl RdrName -> RnM (VectDecl Name, FreeVars) -- FIXME: For the moment, the right-hand side is restricted to be a variable as we cannot properly -- typecheck a complex right-hand side without invoking 'vectType' from the vectoriser. @@ -872,13 +860,13 @@ rnHsVectDecl (HsVectInstIn instTy) } rnHsVectDecl (HsVectInstOut _) = panic "RnSource.rnHsVectDecl: Unexpected 'HsVectInstOut'" -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Type, class and iface sig declarations} -%* * -%********************************************************* +* * +********************************************************* @rnTyDecl@ uses the `global name function' to create a new type declaration in which local names have been replaced by their original @@ -920,8 +908,8 @@ that live on other packages. Since we don't have mutual dependencies across packages, it is safe not to add the dependencies on the .hs-boot stuff to B2. See also Note [Grouping of type and class declarations] in TcTyClsDecls. +-} -\begin{code} isInPackage :: PackageKey -> Name -> Bool isInPackage pkgId nm = case nameModule_maybe nm of Nothing -> False @@ -1196,8 +1184,7 @@ rnFamDecl mb_cls (FamilyDecl { fdLName = tycon, fdTyVars = tyvars rn_info OpenTypeFamily = return (OpenTypeFamily, emptyFVs) rn_info DataFamily = return (DataFamily, emptyFVs) -\end{code} - +{- Note [Stupid theta] ~~~~~~~~~~~~~~~~~~~ Trac #3850 complains about a regression wrt 6.10 for @@ -1206,9 +1193,8 @@ There is no reason not to allow the stupid theta if there are no data constructors. It's still stupid, but does no harm, and I don't want to cause programs to break unnecessarily (notably HList). So if there are no data constructors we allow h98_style = True +-} - -\begin{code} depAnalTyClDecls :: [(LTyClDecl Name, FreeVars)] -> [SCC (LTyClDecl Name)] -- See Note [Dependency analysis of type and class decls] depAnalTyClDecls ds_w_fvs @@ -1236,8 +1222,8 @@ depAnalTyClDecls ds_w_fvs -> do L _ dc <- cons return $ zip (map unLoc $ con_names dc) (repeat data_name) _ -> [] -\end{code} +{- Note [Dependency analysis of type and class decls] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We need to do dependency analysis on type and class declarations @@ -1281,13 +1267,13 @@ the case of staged module compilation (Template Haskell, GHCi). See #8485. With the new lookup process (which includes types declared in other modules), we get better error messages, too. -%********************************************************* -%* * +********************************************************* +* * \subsection{Support code for type/data declarations} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} --------------- badAssocRhs :: [Name] -> RnM () badAssocRhs ns @@ -1396,17 +1382,18 @@ deprecRecSyntax decl badRecResTy :: SDoc -> SDoc badRecResTy doc = ptext (sLit "Malformed constructor signature") $$ doc -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Support code for type/data declarations} -%* * -%********************************************************* +* * +********************************************************* Get the mapping from constructors to fields for this module. It's convenient to do this after the data type decls have been renamed -\begin{code} +-} + extendRecordFieldEnv :: [TyClGroup RdrName] -> [LInstDecl RdrName] -> TcM TcGblEnv extendRecordFieldEnv tycl_decls inst_decls = do { tcg_env <- getGblEnv @@ -1439,15 +1426,15 @@ extendRecordFieldEnv tycl_decls inst_decls fld_set' = extendNameSetList fld_set flds' ; return $ (RecFields env' fld_set') } get_con _ env = return env -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Support code to rename types} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnFds :: [Located (FunDep RdrName)] -> RnM [Located (FunDep Name)] rnFds fds = mapM (wrapLocM rn_fds) fds @@ -1462,21 +1449,20 @@ rnHsTyVars tvs = mapM rnHsTyVar tvs rnHsTyVar :: RdrName -> RnM Name rnHsTyVar tyvar = lookupOccRn tyvar -\end{code} - -%********************************************************* -%* * +{- +********************************************************* +* * findSplice -%* * -%********************************************************* +* * +********************************************************* This code marches down the declarations, looking for the first Template Haskell splice. As it does so it a) groups the declarations into a HsGroup b) runs any top-level quasi-quotes +-} -\begin{code} findSplice :: [LHsDecl RdrName] -> RnM (HsGroup RdrName, Maybe (SpliceDecl RdrName, [LHsDecl RdrName])) findSplice ds = addl emptyRdrGroup ds @@ -1567,4 +1553,3 @@ add_bind _ (ValBindsOut {}) = panic "RdrHsSyn:add_bind" add_sig :: LSig a -> HsValBinds a -> HsValBinds a add_sig s (ValBindsIn bs sigs) = ValBindsIn bs (s:sigs) add_sig _ (ValBindsOut {}) = panic "RdrHsSyn:add_sig" -\end{code} diff --git a/compiler/rename/RnSplice.lhs b/compiler/rename/RnSplice.hs index b0c81b0a92..e147e6a883 100644 --- a/compiler/rename/RnSplice.lhs +++ b/compiler/rename/RnSplice.hs @@ -1,4 +1,3 @@ -\begin{code} {-# LANGUAGE CPP #-} module RnSplice ( @@ -37,9 +36,7 @@ import {-# SOURCE #-} RnExpr ( rnLExpr ) import {-# SOURCE #-} TcExpr ( tcMonoExpr ) import {-# SOURCE #-} TcSplice ( runMetaD, runMetaE, runMetaP, runMetaT, tcTopSpliceExpr ) #endif -\end{code} -\begin{code} #ifndef GHCI rnBracket :: HsExpr RdrName -> HsBracket RdrName -> RnM (HsExpr Name, FreeVars) rnBracket e _ = failTH e "Template Haskell bracket" @@ -60,13 +57,13 @@ rnSplicePat e = failTH e "Template Haskell pattern splice" rnSpliceDecl :: SpliceDecl RdrName -> RnM (SpliceDecl Name, FreeVars) rnSpliceDecl e = failTH e "Template Haskell declaration splice" #else -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * Splices -%* * -%********************************************************* +* * +********************************************************* Note [Free variables of typed splices] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -95,8 +92,8 @@ It's important to wrap renamer calls in checkNoErrs, because the renamer does not fail for out of scope variables etc. Instead it returns a bogus term/type, so that it can report more than one error. We don't want the type checker to see these bogus unbound variables. +-} -\begin{code} rnSpliceGen :: Bool -- Typed splice? -> (HsSplice Name -> RnM (a, FreeVars)) -- Outside brackets, run splice -> (HsSplice Name -> (PendingRnSplice, a)) -- Inside brackets, make it pending @@ -206,8 +203,7 @@ rnSpliceType splice k } ; return (unLoc hs_ty3, fvs) } -\end{code} - +{- Note [rnSplicePat] ~~~~~~~~~~~~~~~~~~ Renaming a pattern splice is a bit tricky, because we need the variables @@ -229,8 +225,7 @@ In any case, when we're done in rnSplicePat, we'll either have a Pat RdrName (the result of running a top-level splice) or a Pat Name (the renamed nested splice). Thus, the awkward return type of rnSplicePat. - -\begin{code} +-} -- | Rename a splice pattern. See Note [rnSplicePat] rnSplicePat :: HsSplice RdrName -> RnM ( Either (Pat RdrName) (Pat Name) @@ -265,9 +260,7 @@ rnSpliceDecl (SpliceDecl (L loc splice) flg) = (PendingRnDeclSplice (PendSplice n e), SpliceDecl(L loc rn_splice) flg) run_decl_splice rn_splice = pprPanic "rnSpliceDecl" (ppr rn_splice) -\end{code} -\begin{code} rnTopSpliceDecls :: HsSplice RdrName -> RnM ([LHsDecl RdrName], FreeVars) -- Declaration splice at the very top level of the module rnTopSpliceDecls (HsSplice _ expr'') @@ -285,15 +278,15 @@ rnTopSpliceDecls (HsSplice _ expr'') (ppr (getLoc expr) $$ (vcat (map ppr decls))) ; return (decls,fvs) } -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * Template Haskell brackets -%* * -%************************************************************************ +* * +************************************************************************ +-} -\begin{code} rnBracket :: HsExpr RdrName -> HsBracket RdrName -> RnM (HsExpr Name, FreeVars) rnBracket e br_body = addErrCtxt (quotationCtxtDoc br_body) $ @@ -401,9 +394,7 @@ rn_bracket _ (DecBrG _) = panic "rn_bracket: unexpected DecBrG" rn_bracket _ (TExpBr e) = do { (e', fvs) <- rnLExpr e ; return (TExpBr e', fvs) } -\end{code} -\begin{code} spliceCtxt :: HsExpr RdrName -> SDoc spliceCtxt expr= hang (ptext (sLit "In the splice:")) 2 (ppr expr) @@ -451,9 +442,7 @@ quotationCtxtDoc br_body -- 2 (char '$' <> pprParendExpr expr) -- , ptext (sLit "To see what the splice expanded to, use -ddump-splices") ] #endif -\end{code} -\begin{code} checkThLocalName :: Name -> RnM () #ifndef GHCI /* GHCI and TH is off */ -------------------------------------- @@ -462,7 +451,7 @@ checkThLocalName _name = return () #else /* GHCI and TH is on */ -checkThLocalName name +checkThLocalName name = do { traceRn (text "checkThLocalName" <+> ppr name) ; mb_local_use <- getStageAndBindLevel name ; case mb_local_use of { @@ -510,8 +499,8 @@ checkCrossStageLifting top_lvl name (Brack _ (RnPendingUntyped ps_var)) checkCrossStageLifting _ _ _ = return () #endif /* GHCI */ -\end{code} +{- Note [Keeping things alive for Template Haskell] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider @@ -571,4 +560,4 @@ Examples: \y. [| \x. $(f 'y) |] -- Not ok (bind =1, use = 1) [| \x. $(f 'x) |] -- OK (bind = 2, use = 1) - +-} diff --git a/compiler/rename/RnSplice.lhs-boot b/compiler/rename/RnSplice.hs-boot index de6da775d2..ece78f8408 100644 --- a/compiler/rename/RnSplice.lhs-boot +++ b/compiler/rename/RnSplice.hs-boot @@ -1,4 +1,3 @@ -\begin{code} module RnSplice where import HsSyn @@ -14,4 +13,3 @@ rnSpliceType :: HsSplice RdrName -> PostTc Name Kind rnSplicePat :: HsSplice RdrName -> RnM ( Either (Pat RdrName) (Pat Name) , FreeVars ) rnSpliceDecl :: SpliceDecl RdrName -> RnM (SpliceDecl Name, FreeVars) -\end{code} diff --git a/compiler/rename/RnTypes.lhs b/compiler/rename/RnTypes.hs index d0877dc423..9eb2581748 100644 --- a/compiler/rename/RnTypes.lhs +++ b/compiler/rename/RnTypes.hs @@ -1,9 +1,9 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -% +{- +(c) The GRASP/AQUA Project, Glasgow University, 1992-1998 + \section[RnSource]{Main pass of renamer} +-} -\begin{code} {-# LANGUAGE CPP #-} module RnTypes ( @@ -50,18 +50,18 @@ import Data.List ( nub, nubBy ) import Control.Monad ( unless, when ) #include "HsVersions.h" -\end{code} +{- These type renamers are in a separate module, rather than in (say) RnSource, to break several loop. -%********************************************************* -%* * +********************************************************* +* * \subsection{Renaming types} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnHsSigType :: SDoc -> LHsType RdrName -> RnM (LHsType Name, FreeVars) -- rnHsSigType is used for source-language type signatures, -- which use *implicit* universal quantification. @@ -81,8 +81,8 @@ rnLHsInstType doc_str ty badInstTy :: LHsType RdrName -> SDoc badInstTy ty = ptext (sLit "Malformed instance:") <+> ppr ty -\end{code} +{- rnHsType is here because we call it from loadInstDecl, and I didn't want a gratuitous knot. @@ -104,8 +104,8 @@ f :: forall a. a -> (() => b) binds "a" and "b" The -fwarn-context-quantification flag warns about this situation. See rnHsTyKi for case HsForAllTy Qualified. +-} -\begin{code} rnLHsTyKi :: Bool -- True <=> renaming a type, False <=> a kind -> HsDocContext -> LHsType RdrName -> RnM (LHsType Name, FreeVars) rnLHsTyKi isType doc (L loc ty) @@ -299,7 +299,7 @@ rnHsTyKi isType doc (HsQuasiQuoteTy qq) = ASSERT( isType ) do { ty <- runQuasiQuoteType qq -- Wrap the result of the quasi-quoter in parens so that we don't - -- lose the outermost location set by runQuasiQuote (#7918) + -- lose the outermost location set by runQuasiQuote (#7918) ; rnHsType doc (HsParTy ty) } rnHsTyKi isType _ (HsCoreTy ty) @@ -344,10 +344,7 @@ rnTyVar is_type rdr_name rnLHsTypes :: HsDocContext -> [LHsType RdrName] -> RnM ([LHsType Name], FreeVars) rnLHsTypes doc tys = mapFvRn (rnLHsType doc) tys -\end{code} - -\begin{code} rnForAll :: HsDocContext -> HsExplicitFlag -> Maybe SrcSpan -- Location of an extra-constraints wildcard -> [RdrName] -- Kind variables @@ -515,15 +512,15 @@ dataKindsErr is_type thing where what | is_type = ptext (sLit "type") | otherwise = ptext (sLit "kind") -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Contexts and predicates} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} rnConDeclFields :: HsDocContext -> [LConDeclField RdrName] -> RnM ([LConDeclField Name], FreeVars) rnConDeclFields doc fields = mapFvRn (rnField doc) fields @@ -540,14 +537,13 @@ rnContext :: HsDocContext -> LHsContext RdrName -> RnM (LHsContext Name, FreeVar rnContext doc (L loc cxt) = do { (cxt', fvs) <- rnLHsTypes doc cxt ; return (L loc cxt', fvs) } -\end{code} - -%************************************************************************ -%* * +{- +************************************************************************ +* * Fixities and precedence parsing -%* * -%************************************************************************ +* * +************************************************************************ @mkOpAppRn@ deals with operator fixities. The argument expressions are assumed to be already correctly arranged. It needs the fixities @@ -566,8 +562,8 @@ is always read in as mkHsOpTyRn rearranges where necessary. The two arguments have already been renamed and rearranged. It's made rather tiresome by the presence of ->, which is a separate syntactic construct. +-} -\begin{code} --------------- -- Building (ty1 `op1` (ty21 `op2` ty22)) mkHsOpTyRn :: (LHsType Name -> LHsType Name -> HsType Name) @@ -795,11 +791,9 @@ checkSectionPrec direction section op arg || (op_prec == arg_prec && direction == assoc)) (sectionPrecErr (op_name, op_fix) (arg_op, arg_fix) section) -\end{code} -Precedence-related error messages +-- Precedence-related error messages -\begin{code} precParseErr :: (Name, Fixity) -> (Name, Fixity) -> RnM () precParseErr op1@(n1,_) op2@(n2,_) | isUnboundName n1 || isUnboundName n2 @@ -825,15 +819,15 @@ ppr_opfix (op, fixity) = pp_op <+> brackets (ppr fixity) where pp_op | op == negateName = ptext (sLit "prefix `-'") | otherwise = quotes (ppr op) -\end{code} -%********************************************************* -%* * +{- +********************************************************* +* * \subsection{Errors} -%* * -%********************************************************* +* * +********************************************************* +-} -\begin{code} warnUnusedForAlls :: SDoc -> LHsTyVarBndrs RdrName -> [RdrName] -> TcM () warnUnusedForAlls in_doc bound mentioned_rdrs = whenWOptM Opt_WarnUnusedMatches $ @@ -874,13 +868,13 @@ opTyErr op ty@(HsOpTy ty1 _ _) forall_head (L _ (HsAppTy ty _)) = forall_head ty forall_head _other = False opTyErr _ ty = pprPanic "opTyErr: Not an op" (ppr ty) -\end{code} -%************************************************************************ -%* * +{- +************************************************************************ +* * Finding the free type variables of a (HsType RdrName) -%* * -%************************************************************************ +* * +************************************************************************ Note [Kind and type-variable binders] @@ -910,8 +904,8 @@ In general we want to walk over a type, and find Hence we returns a pair (kind-vars, type vars) See also Note [HsBSig binder lists] in HsTypes +-} -\begin{code} type FreeKiTyVars = ([RdrName], [RdrName]) filterInScope :: LocalRdrEnv -> FreeKiTyVars -> FreeKiTyVars @@ -1082,5 +1076,3 @@ extractWildcards ty return (nwcs, awcs, tys') goList f tys = do (nwcs, awcs, tys') <- extList tys return (nwcs, awcs, L l $ f tys') - -\end{code} |