diff options
author | partain <unknown> | 1996-06-26 10:30:32 +0000 |
---|---|---|
committer | partain <unknown> | 1996-06-26 10:30:32 +0000 |
commit | 26741ec416bae2c502ef00a2ba0e79050a32cb67 (patch) | |
tree | c07e46b823d29a16838533a17659ed3b28e9f328 /ghc/compiler/rename | |
parent | ae45ff0e9831a0dc862a5d68d03e355d7e323c62 (diff) | |
download | haskell-26741ec416bae2c502ef00a2ba0e79050a32cb67.tar.gz |
[project @ 1996-06-26 10:26:00 by partain]
SLPJ 1.3 changes through 96/06/25
Diffstat (limited to 'ghc/compiler/rename')
-rw-r--r-- | ghc/compiler/rename/ParseIface.y | 50 | ||||
-rw-r--r-- | ghc/compiler/rename/ParseUtils.lhs | 53 | ||||
-rw-r--r-- | ghc/compiler/rename/Rename.lhs | 22 | ||||
-rw-r--r-- | ghc/compiler/rename/RnBinds.lhs | 2 | ||||
-rw-r--r-- | ghc/compiler/rename/RnExpr.lhs | 2 | ||||
-rw-r--r-- | ghc/compiler/rename/RnHsSyn.lhs | 12 | ||||
-rw-r--r-- | ghc/compiler/rename/RnIfaces.lhs | 200 | ||||
-rw-r--r-- | ghc/compiler/rename/RnLoop_1_3.lhi | 5 | ||||
-rw-r--r-- | ghc/compiler/rename/RnMonad.lhs | 37 | ||||
-rw-r--r-- | ghc/compiler/rename/RnNames.lhs | 47 | ||||
-rw-r--r-- | ghc/compiler/rename/RnSource.lhs | 95 | ||||
-rw-r--r-- | ghc/compiler/rename/RnUtils.lhs | 29 |
12 files changed, 353 insertions, 201 deletions
diff --git a/ghc/compiler/rename/ParseIface.y b/ghc/compiler/rename/ParseIface.y index bc4137d409..935c227128 100644 --- a/ghc/compiler/rename/ParseIface.y +++ b/ghc/compiler/rename/ParseIface.y @@ -12,7 +12,7 @@ import RdrHsSyn -- oodles of synonyms import HsPragmas ( noGenPragmas ) import Bag ( emptyBag, unitBag, snocBag ) -import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM ) +import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap ) import Name ( ExportFlag(..), mkTupNameStr, preludeQual, RdrName(..){-instance Outputable:ToDo:rm-} ) @@ -54,6 +54,7 @@ parseIface = parseIToks . lexIface DCOLON { ITdcolon } DOTDOT { ITdotdot } EQUAL { ITequal } + FORALL { ITforall } INFIX { ITinfix } INFIXL { ITinfixl } INFIXR { ITinfixr } @@ -228,8 +229,10 @@ class :: { (RdrName, RdrName) } class : gtycon VARID { ($1, Unqual $2) } ctype :: { RdrNamePolyType } -ctype : context DARROW type { HsPreForAllTy $1 $3 } - | type { HsPreForAllTy [] $1 } +ctype : FORALL OBRACK tyvars CBRACK context DARROW type { HsForAllTy (map Unqual $3) $5 $7 } + | FORALL OBRACK tyvars CBRACK type { HsForAllTy (map Unqual $3) [] $5 } + | context DARROW type {{-ToDo:rm-} HsPreForAllTy $1 $3 } + | type {{-ToDo:change-} HsPreForAllTy [] $1 } type :: { RdrNameMonoType } type : btype { $1 } @@ -313,13 +316,9 @@ btyconapp :: { (RdrName, [RdrNameBangType]) } btyconapp : gtycon { ($1, []) } | btyconapp batype { case $1 of (tc,tys) -> (tc, tys ++ [$2]) } -bbtype :: { RdrNameBangType } -bbtype : btype { Unbanged (HsPreForAllTy [] $1) } - | BANG atype { Banged (HsPreForAllTy [] $2) } - batype :: { RdrNameBangType } -batype : atype { Unbanged (HsPreForAllTy [] $1) } - | BANG atype { Banged (HsPreForAllTy [] $2) } +batype : atype { Unbanged (HsForAllTy [{-ToDo:tvs-}] [] $1) } + | BANG atype { Banged (HsForAllTy [{-ToDo:tvs-}] [] $2) } batypes :: { [RdrNameBangType] } batypes : batype { [$1] } @@ -330,8 +329,8 @@ fields : field { [$1] } | fields COMMA field { $1 ++ [$3] } field :: { ([RdrName], RdrNameBangType) } -field : var DCOLON type { ([$1], Unbanged (HsPreForAllTy [] $3)) } - | var DCOLON BANG atype { ([$1], Banged (HsPreForAllTy [] $4)) } +field : var DCOLON type { ([$1], Unbanged (HsForAllTy [{-ToDo:tvs-}] [] $3)) } + | var DCOLON BANG atype { ([$1], Banged (HsForAllTy [{-ToDo:tvs-}] [] $4)) } constr1 :: { (RdrName, RdrNameMonoType) } constr1 : gtycon atype { ($1, $2) } @@ -347,11 +346,14 @@ qname : QVARID { $1 } | QCONSYM { $1 } name :: { FAST_STRING } -name : VARID { $1 } - | CONID { $1 } - | VARSYM { $1 } - | BANG { SLIT("!"){-sigh, double-sigh-} } - | CONSYM { $1 } +name : VARID { $1 } + | CONID { $1 } + | VARSYM { $1 } + | BANG { SLIT("!"){-sigh, double-sigh-} } + | CONSYM { $1 } + | OBRACK CBRACK { SLIT("[]") } + | OPAREN CPAREN { SLIT("()") } + | OPAREN commas CPAREN { mkTupNameStr $2 } instances_part :: { Bag RdrIfaceInst } instances_part : INSTANCES_PART instdecls { $2 } @@ -362,13 +364,15 @@ instdecls : instd { unitBag $1 } | instdecls instd { $1 `snocBag` $2 } instd :: { RdrIfaceInst } -instd : INSTANCE context DARROW gtycon restrict_inst SEMI { mk_inst $2 $4 $5 } - | INSTANCE gtycon general_inst SEMI { mk_inst [] $2 $3 } +instd : INSTANCE FORALL OBRACK tyvars CBRACK context DARROW gtycon restrict_inst SEMI { mk_inst (Just (map Unqual $4)) $6 $8 $9 } + | INSTANCE FORALL OBRACK tyvars CBRACK gtycon general_inst SEMI { mk_inst (Just (map Unqual $4)) [] $6 $7 } + | INSTANCE context DARROW gtycon restrict_inst SEMI {{-ToDo:rm-} mk_inst Nothing $2 $4 $5 } + | INSTANCE gtycon general_inst SEMI {{-ToDo:rm-} mk_inst Nothing [] $2 $3 } restrict_inst :: { RdrNameMonoType } restrict_inst : gtycon { MonoTyApp $1 [] } - | OPAREN gtyconvars CPAREN { case $2 of (tc,tvs) -> MonoTyApp tc (map en_mono tvs) } - | OPAREN VARID COMMA tyvar_list CPAREN { MonoTupleTy (map en_mono ($2:$4)) } + | OPAREN gtyconvars CPAREN { case $2 of (tc,tvs) -> MonoTyApp tc (map en_mono (reverse tvs)) } + | OPAREN VARID COMMA tyvars CPAREN { MonoTupleTy (map en_mono ($2:$4)) } | OBRACK VARID CBRACK { MonoListTy (en_mono $2) } | OPAREN VARID RARROW VARID CPAREN { MonoFunTy (en_mono $2) (en_mono $4) } @@ -379,9 +383,9 @@ general_inst : gtycon { MonoTyApp $1 [] } | OBRACK type CBRACK { MonoListTy $2 } | OPAREN btype RARROW type CPAREN { MonoFunTy $2 $4 } -tyvar_list :: { [FAST_STRING] } -tyvar_list : VARID { [$1] } - | tyvar_list COMMA VARID { $1 ++ [$3] +tyvars :: { [FAST_STRING] } +tyvars : VARID { [$1] } + | tyvars COMMA VARID { $1 ++ [$3] -------------------------------------------------------------------------- } diff --git a/ghc/compiler/rename/ParseUtils.lhs b/ghc/compiler/rename/ParseUtils.lhs index e71614f7a4..dea7549cc4 100644 --- a/ghc/compiler/rename/ParseUtils.lhs +++ b/ghc/compiler/rename/ParseUtils.lhs @@ -10,13 +10,16 @@ module ParseUtils where IMP_Ubiq(){-uitous-} +IMPORT_1_3(Char(isDigit, isAlpha, isAlphanum, isUpper)) +IMPORT_1_3(List(partition)) + import HsSyn -- quite a bit of stuff import RdrHsSyn -- oodles of synonyms import HsPragmas ( noDataPragmas, noClassPragmas, noClassOpPragmas, noInstancePragmas ) -import ErrUtils ( Error(..) ) +import ErrUtils ( SYN_IE(Error) ) import FiniteMap ( unitFM, listToFM, lookupFM, plusFM, FiniteMap ) import Maybes ( maybeToBool, MaybeErr(..) ) import Name ( isLexConId, isLexVarId, isLexConSym, @@ -27,7 +30,7 @@ import PprStyle ( PprStyle(..) ) -- ToDo: rm debugging import PrelMods ( pRELUDE ) import Pretty ( ppCat, ppPStr, ppInt, ppShow, ppStr ) import SrcLoc ( mkIfaceSrcLoc ) -import Util ( startsWith, isIn, panic, assertPanic ) +import Util ( startsWith, isIn, panic, assertPanic, pprTrace{-ToDo:rm-} ) \end{code} \begin{code} @@ -96,6 +99,7 @@ data IfaceToken | ITinfixl | ITinfixr | ITinfix + | ITforall | ITbang -- magic symbols | ITvbar | ITdcolon @@ -205,15 +209,22 @@ mk_class ctxt (qclas@(Qual mod clas), tyvar) ops_and_sigs where opify (Sig f ty _ loc) = ClassOpSig f ty noClassOpPragmas loc -mk_inst :: RdrNameContext +mk_inst :: Maybe [RdrName] -- ToDo: de-maybe + -> RdrNameContext -> RdrName -- class -> RdrNameMonoType -- fish the tycon out yourself... -> RdrIfaceInst -mk_inst ctxt qclas@(Qual cmod cname) mono_ty - = InstSig qclas (tycon_name mono_ty) mkIfaceSrcLoc $ \ mod -> - InstDecl qclas (HsPreForAllTy ctxt mono_ty) - EmptyMonoBinds False mod [{-sigs-}] +mk_inst tvs ctxt qclas@(Qual cmod cname) mono_ty + = let + ty = case tvs of + Nothing -> HsPreForAllTy ctxt mono_ty -- ToDo: get rid of this + Just ts -> HsForAllTy ts ctxt mono_ty + in + -- pprTrace "mk_inst:" (ppr PprDebug ty) $ + InstSig qclas (tycon_name mono_ty) mkIfaceSrcLoc $ \ mod -> + InstDecl qclas ty + EmptyMonoBinds False{-not from_here-} mod [{-sigs-}] noInstancePragmas mkIfaceSrcLoc where tycon_name (MonoTyApp tc _) = tc @@ -277,10 +288,8 @@ lexIface input ITinteger (read num) : lexIface rest } ----------- - is_var_sym '_' = True - is_var_sym '\'' = True - is_var_sym '#' = True -- for Glasgow-extended names - is_var_sym c = isAlphanum c + is_var_sym c = isAlphanum c || c `elem` "_'#" + -- the last few for for Glasgow-extended names is_var_sym1 '\'' = False is_var_sym1 '#' = False @@ -289,6 +298,15 @@ lexIface input is_sym_sym c = c `elem` ":!#$%&*+./<=>?@\\^|-~" -- ToDo: add ISOgraphic + is_list_sym '[' = True + is_list_sym ']' = True + is_list_sym _ = False + + is_tuple_sym '(' = True + is_tuple_sym ')' = True + is_tuple_sym ',' = True + is_tuple_sym _ = False + ------------ lex_word str@(c:cs) -- we know we have a capital letter to start = -- we first try for "<module>." on the front... @@ -299,6 +317,8 @@ lexIface input in_the_club [] = panic "lex_word:in_the_club" in_the_club (x:_) | isAlpha x = is_var_sym | is_sym_sym x = is_sym_sym + | x == '[' = is_list_sym + | x == '(' = is_tuple_sym | otherwise = panic ("lex_word:in_the_club="++[x]) module_dot (c:cs) @@ -338,18 +358,20 @@ lexIface input in case module_dot of Nothing -> - categ n (ITconid n) (ITvarid n) (ITconsym n) (ITvarsym n) + categ f n (ITconid n) (ITvarid n) (ITconsym n) (ITvarsym n) Just m -> let q = Qual m n in - categ n (ITqconid q) (ITqvarid q) (ITqconsym q) (ITqvarsym q) + categ f n (ITqconid q) (ITqvarid q) (ITqconsym q) (ITqvarsym q) ) : lexIface rest ; } ------------ - categ n conid varid consym varsym - = if isLexConId n then conid + categ f n conid varid consym varsym + = if f == '[' || f == '(' then + conid + else if isLexConId n then conid else if isLexVarId n then varid else if isLexConSym n then consym else varsym @@ -367,6 +389,7 @@ lexIface input ,("fixities__", ITfixities) ,("declarations__", ITdeclarations) ,("pragmas__", ITpragmas) + ,("forall__", ITforall) ,("data", ITdata) ,("type", ITtype) diff --git a/ghc/compiler/rename/Rename.lhs b/ghc/compiler/rename/Rename.lhs index d1b2fbc692..8e9c81d350 100644 --- a/ghc/compiler/rename/Rename.lhs +++ b/ghc/compiler/rename/Rename.lhs @@ -8,7 +8,7 @@ module Rename ( renameModule ) where -import PreludeGlaST ( thenPrimIO, newVar, MutableVar(..) ) +import PreludeGlaST ( thenPrimIO ) IMP_Ubiq() @@ -32,16 +32,16 @@ import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), RdrIfaceInst(..), import RnMonad import RnNames ( getGlobalNames, GlobalNameInfo(..) ) import RnSource ( rnSource ) -import RnIfaces ( rnIfaces ) -import RnUtils ( RnEnv(..), extendGlobalRnEnv, emptyRnEnv ) +import RnIfaces ( rnIfaces, initIfaceCache, IfaceCache ) +import RnUtils ( SYN_IE(RnEnv), extendGlobalRnEnv, emptyRnEnv ) import Bag ( isEmptyBag, unionBags, unionManyBags, bagToList, listToBag ) import CmdLineOpts ( opt_HiMap, opt_NoImplicitPrelude ) -import ErrUtils ( Error(..), Warning(..) ) +import ErrUtils ( SYN_IE(Error), SYN_IE(Warning) ) import FiniteMap ( emptyFM, eltsFM, fmToList, lookupFM{-ToDo:rm-} ) import Maybes ( catMaybes ) -import Name ( isLocallyDefined, mkWiredInName, Name, RdrName(..) ) -import PrelInfo ( builtinNameInfo, BuiltinNames(..), BuiltinKeys(..) ) +import Name ( isLocallyDefined, mkWiredInName, Name, RdrName(..), ExportFlag(..) ) +import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import Unique ( ixClassKey ) import UniqFM ( emptyUFM, lookupUFM, addListToUFM_C, eltsUFM ) import UniqSupply ( splitUniqSupply ) @@ -56,6 +56,7 @@ renameModule :: UniqSupply RnEnv, -- final env (for renaming derivings) [Module], -- imported modules; for profiling + Name -> ExportFlag, -- export info (UsagesMap, VersionsMap, -- version info; for usage [Module]), -- instance modules; for iface @@ -83,7 +84,7 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) -} makeHiMap opt_HiMap >>= \ hi_files -> -- pprTrace "HiMap:\n" (ppAboves [ ppCat [ppPStr m, ppStr p] | (m,p) <- fmToList hi_files]) - newVar (emptyFM,emptyFM,hi_files){-init iface cache-} `thenPrimIO` \ iface_cache -> + initIfaceCache modname hi_files >>= \ iface_cache -> fixIO ( \ ~(_, _, _, _, rec_occ_fm, rec_export_fn) -> let @@ -130,10 +131,10 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) top_warns `unionBags` src_warns `unionBags` listToBag occ_warns, occ_fm, export_fn) - }) >>= \ (rn_module, imp_mods, errs_so_far, warns_so_far, occ_fm, _) -> + }) >>= \ (rn_module, imp_mods, errs_so_far, warns_so_far, occ_fm, export_fn) -> if not (isEmptyBag errs_so_far) then - return (rn_panic, rn_panic, rn_panic, rn_panic, errs_so_far, warns_so_far) + return (rn_panic, rn_panic, rn_panic, rn_panic, rn_panic, errs_so_far, warns_so_far) else -- No errors renaming source so rename the interfaces ... @@ -181,7 +182,7 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) | opt_NoImplicitPrelude = [{-no Prelude.hi, no point looking-}] | otherwise - = [ name_fn (mkWiredInName u orig) + = [ name_fn (mkWiredInName u orig ExportAll) | (orig@(OrigName mod str), (u, name_fn)) <- fmToList b_keys, str `notElem` [ SLIT("main"), SLIT("mainPrimIO")] ] in @@ -200,6 +201,7 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) return (rn_module_with_imports, final_env, imp_mods, + export_fn, usage_stuff, errs_so_far `unionBags` iface_errs, warns_so_far `unionBags` iface_warns) diff --git a/ghc/compiler/rename/RnBinds.lhs b/ghc/compiler/rename/RnBinds.lhs index ab0e9eee43..f1618ad2db 100644 --- a/ghc/compiler/rename/RnBinds.lhs +++ b/ghc/compiler/rename/RnBinds.lhs @@ -38,7 +38,7 @@ import PprStyle--ToDo:rm import Pretty import UniqSet ( emptyUniqSet, unitUniqSet, mkUniqSet, unionUniqSets, unionManyUniqSets, - elementOfUniqSet, uniqSetToList, UniqSet(..) ) + elementOfUniqSet, uniqSetToList, SYN_IE(UniqSet) ) import Util ( thenCmp, isIn, removeDups, panic, panic#, assertPanic, pprTrace{-ToDo:rm-} ) \end{code} diff --git a/ghc/compiler/rename/RnExpr.lhs b/ghc/compiler/rename/RnExpr.lhs index 9e2697fde6..220a9456cd 100644 --- a/ghc/compiler/rename/RnExpr.lhs +++ b/ghc/compiler/rename/RnExpr.lhs @@ -31,7 +31,7 @@ import Pretty import UniqFM ( lookupUFM, ufmToList{-ToDo:rm-} ) import UniqSet ( emptyUniqSet, unitUniqSet, unionUniqSets, unionManyUniqSets, - UniqSet(..) + SYN_IE(UniqSet) ) import Util ( Ord3(..), removeDups, panic ) \end{code} diff --git a/ghc/compiler/rename/RnHsSyn.lhs b/ghc/compiler/rename/RnHsSyn.lhs index 596ed5fa4a..e06d1e7182 100644 --- a/ghc/compiler/rename/RnHsSyn.lhs +++ b/ghc/compiler/rename/RnHsSyn.lhs @@ -12,7 +12,7 @@ IMP_Ubiq() import HsSyn -import Id ( isDataCon, GenId, Id(..) ) +import Id ( isDataCon, GenId, SYN_IE(Id) ) import Name ( isLocalName, nameUnique, Name, RdrName(..){-ToDo: rm ..-}, mkLocalName{-ToDo:rm-} ) @@ -92,6 +92,14 @@ isRnImplicit _ = False isRnUnbound (RnUnbound _) = True isRnUnbound _ = False +isRnEntity (WiredInId _) = True +isRnEntity (WiredInTyCon _) = True +isRnEntity (RnName n) = not (isLocalName n) +isRnEntity (RnSyn _) = True +isRnEntity (RnData _ _ _) = True +isRnEntity (RnClass _ _) = True +isRnEntity _ = False + -- Very general NamedThing comparison, used when comparing -- Uniquable things with different types @@ -120,7 +128,7 @@ instance NamedThing RnName where getName (RnImplicit n) = n getName (RnImplicitTyCon n) = n getName (RnImplicitClass n) = n - getName (RnUnbound occ) = pprTrace "getRnName:RnUnbound: " (ppr PprDebug occ) + getName (RnUnbound occ) = --pprTrace "getRnName:RnUnbound: " (ppr PprDebug occ) (case occ of Unqual n -> mkLocalName bottom n False bottom2 Qual m n -> mkLocalName bottom n False bottom2) diff --git a/ghc/compiler/rename/RnIfaces.lhs b/ghc/compiler/rename/RnIfaces.lhs index 3db7db8ce6..965ab3f922 100644 --- a/ghc/compiler/rename/RnIfaces.lhs +++ b/ghc/compiler/rename/RnIfaces.lhs @@ -8,14 +8,14 @@ module RnIfaces ( cachedIface, - cachedDecl, + cachedDecl, CachingResult(..), rnIfaces, - IfaceCache(..) + IfaceCache, initIfaceCache ) where IMP_Ubiq() -import PreludeGlaST ( thenPrimIO, seqPrimIO, readVar, writeVar, MutableVar(..) ) +import PreludeGlaST ( thenPrimIO, seqPrimIO, newVar, readVar, writeVar, MutableVar(..) ) import HsSyn import HsPragmas ( noGenPragmas ) @@ -24,7 +24,7 @@ import RnHsSyn import RnMonad import RnSource ( rnTyDecl, rnClassDecl, rnInstDecl, rnPolyType ) -import RnUtils ( RnEnv(..), emptyRnEnv, lookupRnEnv, lookupTcRnEnv, extendGlobalRnEnv ) +import RnUtils ( SYN_IE(RnEnv), emptyRnEnv, lookupRnEnv, lookupTcRnEnv, extendGlobalRnEnv ) import ParseIface ( parseIface ) import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), RdrIfaceInst(..), VersionsMap(..), UsagesMap(..) @@ -32,7 +32,7 @@ import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), RdrIfaceInst(..), import Bag ( emptyBag, unitBag, consBag, snocBag, unionBags, unionManyBags, isEmptyBag, bagToList ) -import ErrUtils ( Error(..), Warning(..) ) +import ErrUtils ( SYN_IE(Error), SYN_IE(Warning) ) import FiniteMap ( emptyFM, lookupFM, addToFM, addToFM_C, plusFM, eltsFM, fmToList, delListFromFM, sizeFM, foldFM, unitFM, plusFM_C, addListToFM, keysFM{-ToDo:rm-} @@ -42,7 +42,7 @@ import Name ( origName, moduleOf, nameOf, qualToOrigName, OrigName(..), isLexCon, RdrName(..), Name{-instance NamedThing-} ) import PprStyle -- ToDo:rm import Outputable -- ToDo:rm -import PrelInfo ( builtinNameInfo ) +import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames) ) import Pretty import Maybes ( MaybeErr(..) ) import UniqFM ( emptyUFM ) @@ -55,12 +55,22 @@ import Util ( sortLt, removeDups, cmpPString, startsWith, type ModuleToIfaceContents = FiniteMap Module ParsedIface type ModuleToIfaceFilePath = FiniteMap Module FilePath -type IfaceCache - = MutableVar _RealWorld - (ModuleToIfaceContents, -- interfaces for individual interface files - ModuleToIfaceContents, -- merged interfaces based on module name - -- used for extracting info about original names - ModuleToIfaceFilePath) +data IfaceCache + = IfaceCache + Module -- the name of the module being compiled + BuiltinNames -- so we can avoid going after things + -- the compiler already knows about + (MutableVar _RealWorld + (ModuleToIfaceContents, -- interfaces for individual interface files + ModuleToIfaceContents, -- merged interfaces based on module name + -- used for extracting info about original names + ModuleToIfaceFilePath)) + +initIfaceCache mod hi_files + = newVar (emptyFM,emptyFM,hi_files) `thenPrimIO` \ iface_var -> + return (IfaceCache mod b_names iface_var) + where + b_names = case builtinNameInfo of (b_names,_,_) -> b_names \end{code} ********************************************************* @@ -92,13 +102,15 @@ ToDo: Check/Merge duplicate pragmas. \begin{code} -cachedIface :: Bool -- True => want merged interface for original name - -> IfaceCache -- False => want file interface only +cachedIface :: IfaceCache + -> Bool -- True => want merged interface for original name + -- False => want file interface only + -> FAST_STRING -- item that prompted search (debugging only!) -> Module -> IO (MaybeErr ParsedIface Error) -cachedIface want_orig_iface iface_cache modname - = readVar iface_cache `thenPrimIO` \ (iface_fm, orig_fm, file_fm) -> +cachedIface (IfaceCache _ _ iface_var) want_orig_iface item modname + = readVar iface_var `thenPrimIO` \ (iface_fm, orig_fm, file_fm) -> case (lookupFM iface_fm modname) of Just iface -> return (want_iface iface orig_fm) @@ -106,7 +118,7 @@ cachedIface want_orig_iface iface_cache modname case (lookupFM file_fm modname) of Nothing -> return (Failed (noIfaceErr modname)) Just file -> - readIface file modname >>= \ read_iface -> + readIface file modname item >>= \ read_iface -> case read_iface of Failed err -> -- pprTrace "module-file map:\n" (ppAboves [ppCat [ppPStr m, ppStr f] | (m,f) <- fmToList file_fm]) $ return (Failed err) @@ -115,7 +127,7 @@ cachedIface want_orig_iface iface_cache modname iface_fm' = addToFM iface_fm modname iface orig_fm' = addToFM_C mergeIfaces orig_fm (iface_mod iface) iface in - writeVar iface_cache (iface_fm', orig_fm', file_fm) `seqPrimIO` + writeVar iface_var (iface_fm', orig_fm', file_fm) `seqPrimIO` return (want_iface iface orig_fm') where want_iface iface orig_fm @@ -161,26 +173,49 @@ mergeIfaces (ParsedIface mod1 (_, files1) _ _ _ _ _ _ fixes1 tdefs1 vdefs1 idefs idecl_nm (ValSig n _ _) = n ---------- +data CachingResult + = CachingFail Error -- tried to find a decl, something went wrong + | CachingHit RdrIfaceDecl -- got it + | CachingAvoided (Maybe (Either RnName RnName)) + -- didn't look in the interface + -- file(s); Nothing => the thing + -- *should* be in the source module; + -- Just (Left ...) => builtin val name; + -- Just (Right ..) => builtin tc name + cachedDecl :: IfaceCache -> Bool -- True <=> tycon or class name -> OrigName - -> IO (MaybeErr RdrIfaceDecl Error) + -> IO CachingResult + +cachedDecl iface_cache@(IfaceCache this_mod (b_val_names,b_tc_names) _) + class_or_tycon name@(OrigName mod str) -cachedDecl iface_cache class_or_tycon name@(OrigName mod str) = -- pprTrace "cachedDecl:" (ppr PprDebug name) $ - cachedIface True iface_cache mod >>= \ maybe_iface -> - case maybe_iface of - Failed err -> --pprTrace "cachedDecl:fail:" (ppr PprDebug orig) $ - return (Failed err) - Succeeded (ParsedIface _ _ _ _ _ _ exps _ _ tdefs vdefs _ _) -> - case (lookupFM (if class_or_tycon then tdefs else vdefs) str) of - Just decl -> return (Succeeded decl) - Nothing -> return (Failed (noDeclInIfaceErr mod str)) + if mod == this_mod then -- some i/face has made a reference + return (CachingAvoided Nothing) -- to something from this module + else + let + b_env = if class_or_tycon then b_tc_names else b_val_names + in + case (lookupFM b_env name) of + Just rn -> -- in builtins! + return (CachingAvoided (Just ((if class_or_tycon then Right else Left) rn))) + + Nothing -> + cachedIface iface_cache True str mod >>= \ maybe_iface -> + case maybe_iface of + Failed err -> --pprTrace "cachedDecl:fail:" (ppr PprDebug orig) $ + return (CachingFail err) + Succeeded (ParsedIface _ _ _ _ _ _ exps _ _ tdefs vdefs _ _) -> + case (lookupFM (if class_or_tycon then tdefs else vdefs) str) of + Just decl -> return (CachingHit decl) + Nothing -> return (CachingFail (noDeclInIfaceErr mod str)) ---------- cachedDeclByType :: IfaceCache -> RnName{-NB: diff type than cachedDecl -} - -> IO (MaybeErr RdrIfaceDecl Error) + -> IO CachingResult cachedDeclByType iface_cache rn -- the idea is: check that, e.g., if we're given an @@ -189,11 +224,12 @@ cachedDeclByType iface_cache rn = cachedDecl iface_cache (isRnTyConOrClass rn) (origName "cachedDeclByType" rn) >>= \ maybe_decl -> let return_maybe_decl = return maybe_decl - return_failed msg = return (Failed msg) + return_failed msg = return (CachingFail msg) in case maybe_decl of - Failed io_msg -> return_failed (ifaceIoErr io_msg rn) - Succeeded if_decl -> + CachingAvoided _ -> return_maybe_decl + CachingFail io_msg -> return_failed (ifaceIoErr io_msg rn) + CachingHit if_decl -> case rn of WiredInId _ -> return_failed (ifaceLookupWiredErr "value" rn) WiredInTyCon _ -> return_failed (ifaceLookupWiredErr "type constructor" rn) @@ -234,16 +270,16 @@ cachedDeclByType iface_cache rn \end{code} \begin{code} -readIface :: FilePath -> Module -> IO (MaybeErr ParsedIface Error) +readIface :: FilePath -> Module -> FAST_STRING -> IO (MaybeErr ParsedIface Error) -readIface file modname - = hPutStr stderr (" reading "++file) >> +readIface file modname item + = --hPutStr stderr (" reading "++file++" ("++ _UNPK_ item ++")") >> readFile file `thenPrimIO` \ read_result -> case read_result of Left err -> return (Failed (cannaeReadErr file err)) - Right contents -> hPutStr stderr ".." >> + Right contents -> --hPutStr stderr ".." >> let parsed = parseIface contents in - hPutStr stderr "..\n" >> + --hPutStr stderr "..\n" >> return ( case parsed of Failed _ -> parsed @@ -392,11 +428,15 @@ rnIfaces iface_cache imp_mods us cachedDeclByType iface_cache n >>= \ maybe_ans -> case maybe_ans of - Failed err -> -- add the error, but keep going: - --pprTrace "do_decls:cache error:" (ppr PprDebug n) $ - do_decls ns down (add_err err to_return) + CachingAvoided _ -> + pprTrace "do_decls:caching avoided:" (ppr PprDebug n) $ + do_decls ns down to_return + + CachingFail err -> -- add the error, but keep going: + --pprTrace "do_decls:cache error:" (ppr PprDebug n) $ + do_decls ns down (add_err err to_return) - Succeeded iface_decl -> -- something needing renaming! + CachingHit iface_decl -> -- something needing renaming! let (us1, us2) = splitUniqSupply (uniqsupply down) in @@ -579,21 +619,22 @@ sub (val_ment, tc_ment) (val_defds, tc_defds) \begin{code} cacheInstModules :: IfaceCache -> [Module] -> IO (Bag Error) -cacheInstModules iface_cache imp_mods - = readVar iface_cache `thenPrimIO` \ (iface_fm, _, _) -> + +cacheInstModules iface_cache@(IfaceCache _ _ iface_var) imp_mods + = readVar iface_var `thenPrimIO` \ (iface_fm, _, _) -> let imp_ifaces = [ iface | Just iface <- map (lookupFM iface_fm) imp_mods ] (imp_imods, _) = removeDups cmpPString (bagToList (unionManyBags (map get_ims imp_ifaces))) get_ims (ParsedIface _ _ _ _ _ _ _ ims _ _ _ _ _) = ims in --pprTrace "cacheInstModules:" (ppCat (map ppPStr imp_imods)) $ - accumulate (map (cachedIface False iface_cache) imp_imods) >>= \ err_or_ifaces -> + accumulate (map (cachedIface iface_cache False SLIT("instance_modules")) imp_imods) >>= \ err_or_ifaces -> -- Sanity Check: -- Assert that instance modules given by direct imports contains -- instance modules extracted from all visited modules - readVar iface_cache `thenPrimIO` \ (all_iface_fm, _, _) -> + readVar iface_var `thenPrimIO` \ (all_iface_fm, _, _) -> let all_ifaces = eltsFM all_iface_fm (all_imods, _) = removeDups cmpPString (bagToList (unionManyBags (map get_ims (all_ifaces)))) @@ -625,21 +666,22 @@ rnIfaceInstStuff RnEnv, -- final occ env [RnName]) -- new unknown names -rnIfaceInstStuff iface_cache modname us occ_env done_inst_env to_return +rnIfaceInstStuff iface_cache@(IfaceCache _ _ iface_var) modname us occ_env done_inst_env to_return = -- all the instance decls we might even want to consider -- are in the ParsedIfaces that are in our cache - readVar iface_cache `thenPrimIO` \ (_, orig_iface_fm, _) -> + readVar iface_var `thenPrimIO` \ (_, orig_iface_fm, _) -> let all_ifaces = eltsFM orig_iface_fm - all_insts = unionManyBags (map get_insts all_ifaces) - interesting_insts = filter want_inst (bagToList all_insts) + all_insts = concat (map get_insts all_ifaces) + interesting_insts = filter want_inst all_insts -- Sanity Check: -- Assert that there are no more instances for the done instances - claim_done = filter is_done_inst (bagToList all_insts) + claim_done = filter is_done_inst all_insts claim_done_env = foldr add_done_inst emptyFM claim_done + has_val fm (k,i) = case lookupFM fm k of { Nothing -> False; Just v -> i == v } in {- @@ -651,8 +693,8 @@ rnIfaceInstStuff iface_cache modname us occ_env done_inst_env to_return case (initRn False{-iface-} modname occ_env us ( setExtraRn emptyUFM{-no fixities-} $ - mapRn (rnIfaceInst modname) interesting_insts `thenRn` \ insts -> - getImplicitUpRn `thenRn` \ implicits -> + mapRn rnIfaceInst interesting_insts `thenRn` \ insts -> + getImplicitUpRn `thenRn` \ implicits -> returnRn (insts, implicits))) of { ((if_insts, if_implicits), if_errs, if_warns) -> @@ -665,14 +707,14 @@ rnIfaceInstStuff iface_cache modname us occ_env done_inst_env to_return eltsFM (fst if_implicits) ++ eltsFM (snd if_implicits)) } where - get_insts (ParsedIface _ _ _ _ _ _ _ _ _ _ _ insts _) = insts + get_insts (ParsedIface imod _ _ _ _ _ _ _ _ _ _ insts _) = [(imod, inst) | inst <- bagToList insts] tycon_class clas tycon = (qualToOrigName clas, qualToOrigName tycon) - add_done_inst (InstSig clas tycon _ _) inst_env + add_done_inst (_, InstSig clas tycon _ _) inst_env = addToFM_C (+) inst_env (tycon_class clas tycon) 1 - is_done_inst (InstSig clas tycon _ _) + is_done_inst (_, InstSig clas tycon _ _) = maybeToBool (lookupFM done_inst_env (tycon_class clas tycon)) add_imp_occs (val_imps, tc_imps) occ_env @@ -683,7 +725,7 @@ rnIfaceInstStuff iface_cache modname us occ_env done_inst_env to_return de_orig imps = [ (Qual m n, v) | (OrigName m n, v) <- fmToList imps ] -- again, this hackery because we are reusing the RnEnv technology - want_inst i@(InstSig clas tycon _ _) + want_inst i@(imod, InstSig clas tycon _ _) = -- it's a "good instance" (one to hang onto) if we have a -- chance of referring to *both* the class and tycon later on ... --pprTrace "want_inst:" (ppCat [ppr PprDebug clas, ppr PprDebug tycon, ppr PprDebug (mentionable tycon), ppr PprDebug (mentionable clas), ppr PprDebug(is_done_inst i)]) $ @@ -710,9 +752,9 @@ rnIfaceInstStuff iface_cache modname us occ_env done_inst_env to_return \end{code} \begin{code} -rnIfaceInst :: Module -> RdrIfaceInst -> RnM_Fixes _RealWorld RenamedInstDecl +rnIfaceInst :: (Module, RdrIfaceInst) -> RnM_Fixes _RealWorld RenamedInstDecl -rnIfaceInst mod (InstSig _ _ _ inst_decl) = rnInstDecl (inst_decl mod) +rnIfaceInst (imod, InstSig _ _ _ inst_decl) = rnInstDecl (inst_decl imod) \end{code} \begin{code} @@ -730,13 +772,13 @@ finalIfaceInfo :: VersionsMap, -- info about version numbers [Module]) -- special instance modules -finalIfaceInfo iface_cache modname if_final_env@((qual, unqual, tc_qual, tc_unqual), stack) if_instdecls +finalIfaceInfo iface_cache@(IfaceCache _ _ iface_var) modname if_final_env@((qual, unqual, tc_qual, tc_unqual), stack) if_instdecls = -- pprTrace "usageIf:qual:" (ppCat [ppBesides[ppPStr m,ppChar '.',ppPStr n] | (n,m) <- keysFM qual]) $ -- pprTrace "usageIf:unqual:" (ppCat (map ppPStr (keysFM unqual))) $ -- pprTrace "usageIf:tc_qual:" (ppCat [ppBesides[ppPStr m,ppChar '.',ppPStr n] | (n,m) <- keysFM tc_qual]) $ -- pprTrace "usageIf:tc_unqual:" (ppCat (map ppPStr (keysFM tc_unqual))) $ - readVar iface_cache `thenPrimIO` \ (_, orig_iface_fm, _) -> + readVar iface_var `thenPrimIO` \ (_, orig_iface_fm, _) -> let all_ifaces = eltsFM orig_iface_fm -- all the interfaces we have looked at @@ -771,28 +813,26 @@ finalIfaceInfo iface_cache modname if_final_env@((qual, unqual, tc_qual, tc_unqu | m == modname -- this module => add to "versions" = (usages, addToFM versions n 1{-stub-}) | otherwise -- from another module => add to "usages" - = (add_to_usages usages key, versions) + = case (add_to_usages usages key) of + Nothing -> as_before + Just new_usages -> (new_usages, versions) where add_to_usages usages key@(n,m) - = let - mod_v = case (lookupFM big_mv_map m) of - Nothing -> pprTrace "big_mv_map:miss? " (ppPStr m) $ - 1 - Just nv -> nv - key_v = case (lookupFM big_version_map key) of - Nothing -> pprTrace "big_version_map:miss? " (ppCat [ppPStr n, ppPStr m]) $ - 1 - Just nv -> nv - in - addToFM usages m ( - case (lookupFM usages m) of - Nothing -> -- nothing for this module yet... - (mod_v, unitFM n key_v) - - Just (mversion, mstuff) -> -- the "new" stuff will shadow the old - ASSERT(mversion == mod_v) - (mversion, addToFM mstuff n key_v) - ) + = case (lookupFM big_mv_map m) of + Nothing -> Nothing + Just mv -> + case (lookupFM big_version_map key) of + Nothing -> Nothing + Just kv -> + Just $ addToFM usages m ( + case (lookupFM usages m) of + Nothing -> -- nothing for this module yet... + (mv, unitFM n kv) + + Just (mversion, mstuff) -> -- the "new" stuff will shadow the old + ASSERT(mversion == mv) + (mversion, addToFM mstuff n kv) + ) irrelevant (RnConstr _ _) = True -- We don't report these in their irrelevant (RnField _ _) = True -- own right in usages/etc. diff --git a/ghc/compiler/rename/RnLoop_1_3.lhi b/ghc/compiler/rename/RnLoop_1_3.lhi new file mode 100644 index 0000000000..d87183d6f5 --- /dev/null +++ b/ghc/compiler/rename/RnLoop_1_3.lhi @@ -0,0 +1,5 @@ +\begin{code} +interface RnLoop_1_3 1 +__exports__ +Outputable Outputable (..) +\end{code} diff --git a/ghc/compiler/rename/RnMonad.lhs b/ghc/compiler/rename/RnMonad.lhs index 1d7cc96500..e6b7c93dd2 100644 --- a/ghc/compiler/rename/RnMonad.lhs +++ b/ghc/compiler/rename/RnMonad.lhs @@ -7,7 +7,7 @@ #include "HsVersions.h" module RnMonad ( - RnMonad(..), RnM(..), RnM_Fixes(..), RnDown, SST_R, + SYN_IE(RnMonad), SYN_IE(RnM), SYN_IE(RnM_Fixes), RnDown, SST_R, initRn, thenRn, thenRn_, andRn, returnRn, mapRn, mapAndUnzipRn, mapAndUnzip3Rn, @@ -16,7 +16,7 @@ module RnMonad ( setExtraRn, getExtraRn, getRnEnv, getModuleRn, pushSrcLocRn, getSrcLocRn, getSourceRn, getOccurrenceUpRn, - getImplicitUpRn, ImplicitEnv(..), emptyImplicitEnv, + getImplicitUpRn, SYN_IE(ImplicitEnv), emptyImplicitEnv, rnGetUnique, rnGetUniques, newLocalNames, @@ -24,13 +24,14 @@ module RnMonad ( lookupTyCon, lookupClass, lookupTyConOrClass, extendSS2, extendSS, - TyVarNamesEnv(..), mkTyVarNamesEnv, domTyVarNamesEnv, + SYN_IE(TyVarNamesEnv), mkTyVarNamesEnv, domTyVarNamesEnv, lookupTyVarName, nullTyVarNamesEnv, catTyVarNamesEnvs, fixIO ) where IMP_Ubiq(){-uitous-} +IMPORT_1_3(GHCbase(fixIO)) import SST @@ -40,7 +41,7 @@ import RnHsSyn ( RnName, mkRnName, mkRnUnbound, mkRnImplicit, isRnLocal, isRnWired, isRnTyCon, isRnClass, isRnTyConOrClass, isRnConstr, isRnField, isRnClassOp, RenamedFixityDecl(..) ) -import RnUtils ( RnEnv(..), extendLocalRnEnv, +import RnUtils ( SYN_IE(RnEnv), extendLocalRnEnv, lookupRnEnv, lookupGlobalRnEnv, lookupTcRnEnv, qualNameErr, dupNamesErr ) @@ -48,22 +49,22 @@ import RnUtils ( RnEnv(..), extendLocalRnEnv, import Bag ( Bag, emptyBag, isEmptyBag, snocBag ) import CmdLineOpts ( opt_WarnNameShadowing ) import ErrUtils ( addErrLoc, addShortErrLocLine, addShortWarnLocLine, - Error(..), Warning(..) + SYN_IE(Error), SYN_IE(Warning) ) import FiniteMap ( FiniteMap, emptyFM, lookupFM, addToFM, fmToList{-ToDo:rm-} ) import Maybes ( assocMaybe ) -import Name ( Module(..), RdrName(..), isQual, +import Name ( SYN_IE(Module), RdrName(..), isQual, OrigName(..), Name, mkLocalName, mkImplicitName, getOccName, pprNonSym ) -import PrelInfo ( builtinNameInfo, BuiltinNames(..), BuiltinKeys(..) ) +import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import PrelMods ( pRELUDE ) import PprStyle{-ToDo:rm-} import Outputable{-ToDo:rm-} -import Pretty--ToDo:rm ( Pretty(..), PrettyRep ) +import Pretty--ToDo:rm ( SYN_IE(Pretty), PrettyRep ) import SrcLoc ( SrcLoc, mkUnknownSrcLoc ) import UniqFM ( UniqFM, emptyUFM ) -import UniqSet ( UniqSet(..), mkUniqSet, minusUniqSet ) +import UniqSet ( SYN_IE(UniqSet), mkUniqSet, minusUniqSet ) import UniqSupply ( UniqSupply, getUnique, getUniques, splitUniqSupply ) import Unique ( Unique ) import Util @@ -101,18 +102,23 @@ type ImplicitEnv = (FiniteMap OrigName RnName, FiniteMap OrigName RnName) emptyImplicitEnv :: ImplicitEnv emptyImplicitEnv = (emptyFM, emptyFM) --- With a builtin polymorphic type for _runSST the type for --- initTc should use RnM s r instead of RnM _RealWorld r +-- With a builtin polymorphic type for runSST the type for +-- initTc should use RnM s r instead of RnM RealWorld r +#if __GLASGOW_HASKELL__ >= 200 +# define REAL_WORLD GHCbuiltins.RealWorld +#else +# define REAL_WORLD _RealWorld +#endif initRn :: Bool -- True => Source; False => Iface -> Module -> RnEnv -> UniqSupply - -> RnM _RealWorld r + -> RnM REAL_WORLD r -> (r, Bag Error, Bag Warning) initRn source mod env us do_rn - = _runSST ( + = runSST ( newMutVarSST emptyBag `thenSST` \ occ_var -> newMutVarSST emptyImplicitEnv `thenSST` \ imp_var -> newMutVarSST us `thenSST` \ us_var -> @@ -541,12 +547,17 @@ lookupTyVarName env occ \begin{code} +#if __GLASGOW_HASKELL__ >= 200 + -- can get it from GHCbase +#else fixIO :: (a -> IO a) -> IO a + fixIO k s = let result = k loop s (Right loop, _) = result in result +#endif \end{code} ********************************************************* diff --git a/ghc/compiler/rename/RnNames.lhs b/ghc/compiler/rename/RnNames.lhs index cd256b9feb..55aeb1bec8 100644 --- a/ghc/compiler/rename/RnNames.lhs +++ b/ghc/compiler/rename/RnNames.lhs @@ -20,8 +20,8 @@ import RdrHsSyn import RnHsSyn import RnMonad -import RnIfaces ( IfaceCache(..), cachedIface, cachedDecl ) -import RnUtils ( RnEnv(..), emptyRnEnv, extendGlobalRnEnv, +import RnIfaces ( IfaceCache, cachedIface, cachedDecl, CachingResult(..) ) +import RnUtils ( SYN_IE(RnEnv), emptyRnEnv, extendGlobalRnEnv, lubExportFlag, qualNameErr, dupNamesErr ) import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), ExportsMap(..), RdrIfaceInst ) @@ -29,8 +29,8 @@ import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), ExportsMap(..), RdrIfaceI import Bag ( emptyBag, unitBag, consBag, snocBag, unionBags, unionManyBags, mapBag, filterBag, listToBag, bagToList ) -import CmdLineOpts ( opt_NoImplicitPrelude, opt_CompilingPrelude ) -import ErrUtils ( Error(..), Warning(..), addErrLoc, addShortErrLocLine, addShortWarnLocLine ) +import CmdLineOpts ( opt_NoImplicitPrelude, opt_CompilingGhcInternals ) +import ErrUtils ( SYN_IE(Error), SYN_IE(Warning), addErrLoc, addShortErrLocLine, addShortWarnLocLine ) import FiniteMap ( emptyFM, addToFM, addListToFM, lookupFM, fmToList, eltsFM, delListFromFM, keysFM{-ToDo:rm-} ) import Id ( GenId ) import Maybes ( maybeToBool, catMaybes, MaybeErr(..) ) @@ -41,7 +41,7 @@ import Name ( RdrName(..), Name, isQual, mkTopLevName, mkWiredInName, origName, moduleNamePair, pprNonSym, isLexCon, ExportFlag(..), OrigName(..) ) -import PrelInfo ( BuiltinNames(..), BuiltinKeys(..) ) +import PrelInfo ( SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import PrelMods ( pRELUDE, gHC_BUILTINS, modulesWithBuiltins ) import Pretty import SrcLoc ( SrcLoc, mkBuiltinSrcLoc ) @@ -302,7 +302,7 @@ newGlobalName locn maybe_exp is_val_name (Unqual name) (uniq, is_toplev) = case (lookupFM b_keys orig) of Just (key,_) -> (key, True) - Nothing -> if not opt_CompilingPrelude then (u,True) else -- really here just to save gratuitous lookup + Nothing -> if not opt_CompilingGhcInternals then (u,True) else -- really here just to save gratuitous lookup case (lookupFM (if is_val_name then b_val_names else b_tc_names) orig) of Nothing -> (u, True) Just xx -> (uniqueOf xx, False{-builtin!-}) @@ -313,12 +313,12 @@ newGlobalName locn maybe_exp is_val_name (Unqual name) n = if is_toplev then mkTopLevName uniq orig locn exp (rec_occ_fn n) -- NB: two "n"s - else mkWiredInName uniq orig + else mkWiredInName uniq orig exp in returnRn n newGlobalName locn maybe_exp is_val_name rdr@(Qual mod name) - | opt_CompilingPrelude + | opt_CompilingGhcInternals -- we are actually defining something that compiler knows about (e.g., Bool) = getExtraRn `thenRn` \ ((b_val_names,b_tc_names),b_keys,rec_exp_fn,rec_occ_fn) -> @@ -338,7 +338,7 @@ newGlobalName locn maybe_exp is_val_name rdr@(Qual mod name) n = if is_toplev then mkTopLevName uniq orig locn exp (rec_occ_fn n) -- NB: two "n"s - else mkWiredInName uniq orig + else mkWiredInName uniq orig exp in returnRn n @@ -395,7 +395,7 @@ doImportDecls iface_cache g_info us src_imps -- this ensures that all directly imported modules -- will have their original name iface in scope -- pprTrace "doImportDecls:" (ppCat (map ppPStr imp_mods)) $ - accumulate (map (cachedIface False iface_cache) imp_mods) >> + accumulate (map (cachedIface iface_cache False SLIT("doImportDecls")) imp_mods) >> -- process the imports doImports iface_cache i_info us all_imps @@ -521,7 +521,7 @@ doImport iface_cache info us (ImportDecl mod qual maybe_as maybe_spec src_loc) \ iface -> ([], [], emptyBag)) else --pprTrace "doImport:" (ppPStr mod) $ - cachedIface False iface_cache mod >>= \ maybe_iface -> + cachedIface iface_cache False SLIT("doImport") mod >>= \ maybe_iface -> return (maybe_iface, \ iface -> getOrigIEs iface maybe_spec') ) >>= \ (maybe_iface, do_ies) -> @@ -748,6 +748,7 @@ doOrigIE :: IfaceCache doOrigIE iface_cache info mod src_loc us ie = with_decl iface_cache (ie_name ie) + avoided_fn (\ err -> (emptyBag, emptyBag, emptyBag, unitBag err, emptyBag)) (\ decl -> case initRn True mod emptyRnEnv us (setExtraRn info $ @@ -755,6 +756,14 @@ doOrigIE iface_cache info mod src_loc us ie getIfaceDeclNames ie decl) of ((vals, tcs, imps), errs, warns) -> (vals, tcs, imps, errs, warns)) + where + avoided_fn Nothing -- the thing should be in the source + = (emptyBag, emptyBag, emptyBag, emptyBag, emptyBag) + avoided_fn (Just (Left rn)) -- a builtin value brought into scope + = (unitBag rn, emptyBag, emptyBag, emptyBag, emptyBag) + avoided_fn (Just (Right rn)) -- a builtin tc/class brought into scope + = --pprTrace "avoided:Right:" (ppr PprShowAll rn) $ + (emptyBag, unitBag rn, emptyBag, emptyBag, emptyBag) ------------------------- checkOrigIE :: IfaceCache @@ -763,6 +772,7 @@ checkOrigIE :: IfaceCache checkOrigIE iface_cache (IEThingAll n, ExportAbs) = with_decl iface_cache n + (\ _ -> (emptyBag, emptyBag)) (\ err -> (unitBag (\ mod locn -> err), emptyBag)) (\ decl -> case decl of TypeSig _ _ _ -> (emptyBag, unitBag (allWhenSynImpSpecWarn n)) @@ -773,6 +783,7 @@ checkOrigIE iface_cache (IEThingWith n ns, ExportAbs) checkOrigIE iface_cache (IEThingWith n ns, ExportAll) = with_decl iface_cache n + (\ _ -> (emptyBag, emptyBag)) (\ err -> (unitBag (\ mod locn -> err), emptyBag)) (\ decl -> case decl of NewTypeSig _ con _ _ -> (check_with "constructors" [con] ns, emptyBag) @@ -791,15 +802,17 @@ checkOrigIE iface_cache other ----------------------- with_decl :: IfaceCache -> OrigName - -> (Error -> something) -- if an error... - -> (RdrIfaceDecl -> something) -- if OK... + -> (Maybe (Either RnName RnName) -> something) -- if avoided.. + -> (Error -> something) -- if an error... + -> (RdrIfaceDecl -> something) -- if OK... -> IO something -with_decl iface_cache n do_err do_decl +with_decl iface_cache n do_avoid do_err do_decl = cachedDecl iface_cache (isLexCon (nameOf n)) n >>= \ maybe_decl -> case maybe_decl of - Failed err -> return (do_err err) - Succeeded decl -> return (do_decl decl) + CachingAvoided info -> return (do_avoid info) + CachingFail err -> return (do_err err) + CachingHit decl -> return (do_decl decl) ------------- getFixityDecl :: IfaceCache @@ -812,7 +825,7 @@ getFixityDecl iface_cache rn succeeded infx i = return (Just (infx rn i), emptyBag) in - cachedIface True iface_cache mod >>= \ maybe_iface -> + cachedIface iface_cache True str mod >>= \ maybe_iface -> case maybe_iface of Failed err -> return (Nothing, unitBag err) diff --git a/ghc/compiler/rename/RnSource.lhs b/ghc/compiler/rename/RnSource.lhs index 3831ec031c..ce3359feab 100644 --- a/ghc/compiler/rename/RnSource.lhs +++ b/ghc/compiler/rename/RnSource.lhs @@ -17,13 +17,14 @@ import RdrHsSyn import RnHsSyn import RnMonad import RnBinds ( rnTopBinds, rnMethodBinds ) -import RnUtils ( lookupGlobalRnEnv, lubExportFlag ) +import RnUtils ( getLocalsFromRnEnv, lookupGlobalRnEnv, lubExportFlag ) import Bag ( emptyBag, unitBag, consBag, unionManyBags, unionBags, listToBag, bagToList ) import Class ( derivableClassKeys ) -import CmdLineOpts ( opt_CompilingPrelude ) +import CmdLineOpts ( opt_CompilingGhcInternals ) import ErrUtils ( addErrLoc, addShortErrLocLine, addShortWarnLocLine ) import FiniteMap ( emptyFM, lookupFM, addListToFM_C ) +import Id ( GenId{-instance NamedThing-} ) import ListSetOps ( unionLists, minusList ) import Maybes ( maybeToBool, catMaybes ) import Name ( isLocallyDefined, isLexVarId, getLocalName, ExportFlag(..), @@ -32,11 +33,12 @@ import Outputable -- ToDo:rm import PprStyle -- ToDo:rm import Pretty import SrcLoc ( SrcLoc ) +import TyCon ( tyConDataCons, TyCon{-instance NamedThing-} ) import Unique ( Unique ) import UniqFM ( emptyUFM, addListToUFM_C, listToUFM, plusUFM, lookupUFM, eltsUFM ) -import UniqSet ( UniqSet(..) ) +import UniqSet ( SYN_IE(UniqSet) ) import Util ( isIn, isn'tIn, thenCmp, sortLt, removeDups, mapAndUnzip3, cmpPString, - assertPanic, pprTrace{-ToDo:rm-} ) + panic, assertPanic, pprTrace{-ToDo:rm-} ) \end{code} rnSource `renames' the source module and export list. @@ -121,7 +123,9 @@ rnExports mods unqual_imps Nothing = returnRn (\n -> if isLocallyDefined n then ExportAll else NotExported) rnExports mods unqual_imps (Just exps) - = mapAndUnzipRn (rnIE mods) exps `thenRn` \ (mod_maybes, exp_bags) -> + = getModuleRn `thenRn` \ this_mod -> + getRnEnv `thenRn` \ rn_env -> + mapAndUnzipRn (rnIE mods) exps `thenRn` \ (mod_maybes, exp_bags) -> let (tc_bags, val_bags) = unzip exp_bags tc_names = bagToList (unionManyBags tc_bags) @@ -134,11 +138,17 @@ rnExports mods unqual_imps (Just exps) cmp_fst (x,_) (y,_) = x `cmp` y (uniq_mods, dup_mods) = removeDups cmpPString exp_mods + (expmods_this, expmods_imps) = partition (== this_mod) uniq_mods - -- Get names for exported modules + -- Get names for module This_Mod export + (this_tcs, this_vals) + = if null expmods_this + then ([], []) + else getLocalsFromRnEnv rn_env + -- Get names for exported imported modules (mod_tcs, mod_vals, empty_mods) - = case mapAndUnzip3 get_mod_names uniq_mods of + = case mapAndUnzip3 get_mod_names expmods_imps of (tcs, vals, emptys) -> (concat tcs, concat vals, catMaybes emptys) (unqual_tcs, unqual_vals) = partition (isRnTyConOrClass.snd) (bagToList unqual_imps) @@ -156,12 +166,15 @@ rnExports mods unqual_imps (Just exps) -- Build finite map of exported names to export flag tc_map0 = addListToUFM_C lub_expflag emptyUFM (map pair_fst tc_names) - tc_map = addListToUFM_C lub_expflag tc_map0 (map pair_fst mod_tcs) + tc_map1 = addListToUFM_C lub_expflag tc_map0 (map pair_fst mod_tcs) + tc_map = addListToUFM_C lub_expflag tc_map1 (map (pair_fst.exp_all) this_tcs) val_map0 = addListToUFM_C lub_expflag emptyUFM (map pair_fst val_names) - val_map = addListToUFM_C lub_expflag val_map0 (map pair_fst mod_vals) + val_map1 = addListToUFM_C lub_expflag val_map0 (map pair_fst mod_vals) + val_map = addListToUFM_C lub_expflag val_map1 (map (pair_fst.exp_all) this_vals) - pair_fst p@(f,_) = (f,p) + pair_fst pr@(n,_) = (n,pr) + exp_all rn = (getName rn, ExportAll) lub_expflag (n, flag1) (_, flag2) = (n, lubExportFlag flag1 flag2) -- Check for exporting of duplicate local names @@ -174,8 +187,8 @@ rnExports mods unqual_imps (Just exps) -- Build export flag function final_exp_map = plusUFM tc_map val_map exp_fn n = case lookupUFM final_exp_map n of - Nothing -> NotExported - Just (_,flag) -> flag + Nothing -> NotExported + Just (_,flag) -> flag in getSrcLocRn `thenRn` \ src_loc -> mapRn (addWarnRn . dupNameExportWarn src_loc) dup_tc_names `thenRn_` @@ -192,20 +205,26 @@ rnIE mods (IEVar name) checkIEVar rn `thenRn` \ exps -> returnRn (Nothing, exps) where - checkIEVar (RnName n) = returnRn (emptyBag, unitBag (n,ExportAll)) + checkIEVar (RnName n) = returnRn (emptyBag, unitBag (n,ExportAll)) + checkIEVar (WiredInId i) = returnRn (emptyBag, unitBag (getName i, ExportAll)) checkIEVar rn@(RnClassOp _ _) = getSrcLocRn `thenRn` \ src_loc -> failButContinueRn (emptyBag, emptyBag) (classOpExportErr rn src_loc) - checkIEVar rn = returnRn (emptyBag, emptyBag) + checkIEVar rn@(RnField _ _) = getSrcLocRn `thenRn` \ src_loc -> + failButContinueRn (emptyBag, emptyBag) (fieldExportErr rn src_loc) + checkIEVar rn = --pprTrace "rnIE:IEVar:panic? ToDo?:" (ppr PprDebug rn) $ + returnRn (emptyBag, emptyBag) rnIE mods (IEThingAbs name) = lookupTyConOrClass name `thenRn` \ rn -> checkIEAbs rn `thenRn` \ exps -> returnRn (Nothing, exps) where - checkIEAbs (RnSyn n) = returnRn (unitBag (n,ExportAbs), emptyBag) - checkIEAbs (RnData n _ _) = returnRn (unitBag (n,ExportAbs), emptyBag) - checkIEAbs (RnClass n _) = returnRn (unitBag (n,ExportAbs), emptyBag) - checkIEAbs rn = returnRn (emptyBag, emptyBag) + checkIEAbs (RnSyn n) = returnRn (unitBag (n,ExportAbs), emptyBag) + checkIEAbs (RnData n _ _) = returnRn (unitBag (n,ExportAbs), emptyBag) + checkIEAbs (RnClass n _) = returnRn (unitBag (n,ExportAbs), emptyBag) + checkIEAbs (WiredInTyCon t) = returnRn (unitBag (getName t,ExportAbs), emptyBag) + checkIEAbs rn = --pprTrace "rnIE:IEAbs:panic? ToDo?:" (ppr PprDebug rn) $ + returnRn (emptyBag, emptyBag) rnIE mods (IEThingAll name) = lookupTyConOrClass name `thenRn` \ rn -> @@ -213,14 +232,24 @@ rnIE mods (IEThingAll name) checkImportAll rn `thenRn_` returnRn (Nothing, exps) where - checkIEAll (RnData n cons fields) = returnRn (unitBag (exp_all n), listToBag (map exp_all cons) - `unionBags` - listToBag (map exp_all fields)) - checkIEAll (RnClass n ops) = returnRn (unitBag (exp_all n), listToBag (map exp_all ops)) - checkIEAll rn@(RnSyn n) = getSrcLocRn `thenRn` \ src_loc -> - warnAndContinueRn (unitBag (n, ExportAbs), emptyBag) - (synAllExportErr False{-warning-} rn src_loc) - checkIEAll rn = returnRn (emptyBag, emptyBag) + checkIEAll (RnData n cons fields) + = returnRn (unitBag (exp_all n), + listToBag (map exp_all cons) `unionBags` listToBag (map exp_all fields)) + + checkIEAll (WiredInTyCon t) + = returnRn (unitBag (exp_all (getName t)), listToBag (map exp_all cons)) + where + cons = map getName (tyConDataCons t) + + checkIEAll (RnClass n ops) + = returnRn (unitBag (exp_all n), listToBag (map exp_all ops)) + checkIEAll rn@(RnSyn n) + = getSrcLocRn `thenRn` \ src_loc -> + warnAndContinueRn (unitBag (n, ExportAbs), emptyBag) + (synAllExportErr False{-warning-} rn src_loc) + + checkIEAll rn = pprTrace "rnIE:IEAll:panic? ToDo?:" (ppr PprDebug rn) $ + returnRn (emptyBag, emptyBag) exp_all n = (n, ExportAll) @@ -246,8 +275,10 @@ rnIE mods (IEThingWith name names) checkIEWith rn@(RnSyn _) rns = getSrcLocRn `thenRn` \ src_loc -> failButContinueRn (emptyBag, emptyBag) (synAllExportErr True{-error-} rn src_loc) + checkIEWith (WiredInTyCon _) rns = panic "RnSource.rnIE:checkIEWith:WiredInTyCon:ToDo (boring)" checkIEWith rn rns - = returnRn (emptyBag, emptyBag) + = pprTrace "rnIE:IEWith:panic? ToDo?:" (ppr PprDebug rn) $ + returnRn (emptyBag, emptyBag) exp_all n = (n, ExportAll) @@ -590,8 +621,8 @@ rnFixes fixities rn_fixity_pieces mk_fixity name i fix = getRnEnv `thenRn` \ env -> case lookupGlobalRnEnv env name of - Just res | isLocallyDefined res || opt_CompilingPrelude - -- the opt_CompilingPrelude thing is a *HACK* to get (:)'s + Just res | isLocallyDefined res || opt_CompilingGhcInternals + -- the opt_CompilingGhcInternals thing is a *HACK* to get (:)'s -- fixity decl to go through. It has a builtin name, which -- doesn't respond to isLocallyDefined... sigh. -> returnRn (Just (mk_fixity res i)) @@ -716,7 +747,11 @@ dupLocalsExportErr locn locals@((str,_):_) classOpExportErr op locn = addShortErrLocLine locn $ \ sty -> - ppBesides [ppStr "class operation `", ppr sty op, ppStr "' can only be exported with class"] + ppBesides [ppStr "class operation `", ppr sty op, ppStr "' can only be exported with its class"] + +fieldExportErr op locn + = addShortErrLocLine locn $ \ sty -> + ppBesides [ppStr "field name `", ppr sty op, ppStr "' can only be exported with its data type"] synAllExportErr is_error syn locn = (if is_error then addShortErrLocLine else addShortWarnLocLine) locn $ \ sty -> diff --git a/ghc/compiler/rename/RnUtils.lhs b/ghc/compiler/rename/RnUtils.lhs index 7e50792b88..781aa8bcf8 100644 --- a/ghc/compiler/rename/RnUtils.lhs +++ b/ghc/compiler/rename/RnUtils.lhs @@ -7,10 +7,11 @@ #include "HsVersions.h" module RnUtils ( - RnEnv(..), QualNames(..), - UnqualNames(..), ScopeStack(..), + SYN_IE(RnEnv), SYN_IE(QualNames), + SYN_IE(UnqualNames), SYN_IE(ScopeStack), emptyRnEnv, extendGlobalRnEnv, extendLocalRnEnv, lookupRnEnv, lookupGlobalRnEnv, lookupTcRnEnv, + getLocalsFromRnEnv, lubExportFlag, @@ -19,14 +20,16 @@ module RnUtils ( ) where IMP_Ubiq(){-uitous-} +IMPORT_1_3(List(partition)) import Bag ( Bag, emptyBag, snocBag, unionBags ) -import CmdLineOpts ( opt_CompilingPrelude ) +import CmdLineOpts ( opt_CompilingGhcInternals ) import ErrUtils ( addShortErrLocLine ) import FiniteMap ( FiniteMap, emptyFM, isEmptyFM, - lookupFM, addListToFM, addToFM ) + lookupFM, addListToFM, addToFM, eltsFM ) import Maybes ( maybeToBool ) -import Name ( RdrName(..), isQual, pprNonSym, getLocalName, ExportFlag(..) ) +import Name ( RdrName(..), ExportFlag(..), + isQual, pprNonSym, getLocalName, isLocallyDefined ) import PprStyle ( PprStyle(..) ) import Pretty import RnHsSyn ( RnName ) @@ -56,6 +59,9 @@ extendLocalRnEnv :: Bool -> RnEnv -> [RnName] -> (RnEnv, [RnName]) lookupRnEnv :: RnEnv -> RdrName -> Maybe RnName lookupGlobalRnEnv :: RnEnv -> RdrName -> Maybe RnName lookupTcRnEnv :: RnEnv -> RdrName -> Maybe RnName + +getLocalsFromRnEnv :: RnEnv -> ([RnName], [RnName]) + -- grabs the locally defined names from the unqual envs \end{code} If the @RdrName@ is a @Qual@, @lookupValue@ looks it up in the global @@ -129,8 +135,9 @@ lookupRnEnv ((qual, unqual, _, _), stack) rdr = case rdr of Unqual str -> lookup stack str (lookup unqual str Nothing) Qual mod str -> lookup qual (str,mod) - (if not opt_CompilingPrelude -- see below - then Nothing + (if not opt_CompilingGhcInternals -- see below + then -- pprTrace "lookupRnEnv:" (ppAboves (ppCat [ppPStr mod, ppPStr str] : [ ppCat [ppPStr m, ppPStr s] | (s,m) <- keysFM qual ])) $ + Nothing else lookup unqual str Nothing) where lookup fm thing do_on_fail @@ -143,7 +150,7 @@ lookupGlobalRnEnv ((qual, unqual, _, _), _) rdr Unqual str -> lookupFM unqual str Qual mod str -> case (lookupFM qual (str,mod)) of Just xx -> Just xx - Nothing -> if not opt_CompilingPrelude then + Nothing -> if not opt_CompilingGhcInternals then Nothing else -- "[]" may have turned into "Prelude.[]" and -- we are actually compiling "data [] a = ..."; @@ -156,10 +163,14 @@ lookupTcRnEnv ((_, _, tc_qual, tc_unqual), _) rdr Unqual str -> lookupFM tc_unqual str Qual mod str -> case (lookupFM tc_qual (str,mod)) of -- as above Just xx -> Just xx - Nothing -> if not opt_CompilingPrelude then + Nothing -> if not opt_CompilingGhcInternals then Nothing else lookupFM tc_unqual str + +getLocalsFromRnEnv ((_, vals, _, tcs), _) + = (filter isLocallyDefined (eltsFM vals), + filter isLocallyDefined (eltsFM tcs)) \end{code} ********************************************************* |