diff options
author | partain <unknown> | 1996-07-15 11:34:07 +0000 |
---|---|---|
committer | partain <unknown> | 1996-07-15 11:34:07 +0000 |
commit | 573ef10b2afd99d3c6a36370a9367609716c97d2 (patch) | |
tree | 64c9e918a8738ad9a5ed2a3d55e78c0e2a45086e /ghc/compiler/rename | |
parent | 30f15b4e7d579dc142537342161c460c6b80290b (diff) | |
download | haskell-573ef10b2afd99d3c6a36370a9367609716c97d2.tar.gz |
[project @ 1996-07-15 11:32:34 by partain]
partain changes to 960714
Diffstat (limited to 'ghc/compiler/rename')
-rw-r--r-- | ghc/compiler/rename/ParseUtils.lhs | 4 | ||||
-rw-r--r-- | ghc/compiler/rename/Rename.lhs | 54 | ||||
-rw-r--r-- | ghc/compiler/rename/RnBinds.lhs | 14 | ||||
-rw-r--r-- | ghc/compiler/rename/RnIfaces.lhs | 22 | ||||
-rw-r--r-- | ghc/compiler/rename/RnMonad.lhs | 5 | ||||
-rw-r--r-- | ghc/compiler/rename/RnNames.lhs | 109 | ||||
-rw-r--r-- | ghc/compiler/rename/RnSource.lhs | 45 | ||||
-rw-r--r-- | ghc/compiler/rename/RnUtils.lhs | 83 |
8 files changed, 201 insertions, 135 deletions
diff --git a/ghc/compiler/rename/ParseUtils.lhs b/ghc/compiler/rename/ParseUtils.lhs index 04d4302e91..08266c6016 100644 --- a/ghc/compiler/rename/ParseUtils.lhs +++ b/ghc/compiler/rename/ParseUtils.lhs @@ -313,11 +313,11 @@ lexIface input Just (m,rest) -> lex_name (Just m) (in_the_club rest) rest where in_the_club [] = panic "lex_word:in_the_club" - in_the_club (x:_) | isAlpha x = is_var_sym + in_the_club (x:y) | 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]) + | otherwise = panic ("lex_word:in_the_club="++(x:y)) module_dot (c:cs) = if not (isUpper c) || c == '\'' then diff --git a/ghc/compiler/rename/Rename.lhs b/ghc/compiler/rename/Rename.lhs index 02194ae2ec..3c827c16db 100644 --- a/ghc/compiler/rename/Rename.lhs +++ b/ghc/compiler/rename/Rename.lhs @@ -46,7 +46,7 @@ import Name ( isLocallyDefined, mkWiredInName, getLocalName, isLocalName, Name, RdrName(..), ExportFlag(..) ) import PprStyle -- ToDo:rm -import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) +import PrelInfo ( builtinNameMaps, builtinKeysMap, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import Pretty -- ToDo:rm import Unique ( ixClassKey ) import UniqFM ( emptyUFM, lookupUFM, addListToUFM_C, eltsUFM ) @@ -62,7 +62,10 @@ renameModule :: UniqSupply RnEnv, -- final env (for renaming derivings) [Module], -- imported modules; for profiling - Name -> ExportFlag, -- export info + (Name -> ExportFlag, -- export info + ([(Name,ExportFlag)], + [(Name,ExportFlag)])), + (UsagesMap, VersionsMap, -- version info; for usage [Module]), -- instance modules; for iface @@ -77,29 +80,29 @@ ToDo: Deal with instances (instance version, this module on instance list ???) \begin{code} renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) - = let - (b_names, b_keys, _) = builtinNameInfo + = {- + let pp_pair (n,m) = ppBesides [ppPStr m,ppChar '.',ppPStr n] in - {- - pprTrace "builtins:\n" (case b_names of { (builtin_ids, builtin_tcs) -> + pprTrace "builtins:\n" (case builtinNameMaps of { (builtin_ids, builtin_tcs) -> ppAboves [ ppCat (map pp_pair (keysFM builtin_ids)) , ppCat (map pp_pair (keysFM builtin_tcs)) - , ppCat (map pp_pair (keysFM b_keys)) + , ppCat (map pp_pair (keysFM builtinKeysMap)) ]}) $ -} +-- _scc_ "rnGlobalNames" makeHiMap opt_HiMap >>= \ hi_files -> -- pprTrace "HiMap:\n" (ppAboves [ ppCat [ppPStr m, ppStr p] | (m,p) <- fmToList hi_files]) initIfaceCache modname hi_files >>= \ iface_cache -> - fixIO ( \ ~(_, _, _, _, rec_occ_fm, rec_export_fn) -> + fixIO ( \ ~(_, _, _, _, rec_occ_fm, ~(rec_export_fn,_)) -> let rec_occ_fn :: Name -> [RdrName] rec_occ_fn n = case lookupUFM rec_occ_fm n of Nothing -> [] Just (rn,occs) -> occs - global_name_info = (b_names, b_keys, rec_export_fn, rec_occ_fn) + global_name_info = (builtinNameMaps, builtinKeysMap, rec_export_fn, rec_occ_fn) in getGlobalNames iface_cache global_name_info us1 input >>= \ (occ_env, imp_mods, unqual_imps, imp_fixes, top_errs, top_warns) -> @@ -109,12 +112,12 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) else -- No top-level name errors so rename source ... +-- _scc_ "rnSource" case initRn True modname occ_env us2 (rnSource imp_mods unqual_imps imp_fixes input) of { - ((rn_module, export_fn, src_occs), src_errs, src_warns) -> + ((rn_module, export_fn, module_dotdots, src_occs), src_errs, src_warns) -> --pprTrace "renameModule:" (ppCat (map (ppr PprDebug . fst) (bagToList src_occs))) $ - let occ_fm :: UniqFM (RnName, [RdrName]) @@ -129,21 +132,25 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) GT__ -> x : insert new xs occ_warns = map multipleOccWarn (filter multiple_occs (eltsUFM occ_fm)) - multiple_occs (rn, (o1:o2:_)) = True + + multiple_occs (rn, (o1:o2:_)) = getLocalName o1 /= SLIT("negate") + -- the user is rarely responsible if + -- "negate" is mentioned in multiple ways multiple_occs _ = False in return (rn_module, imp_mods, top_errs `unionBags` src_errs, top_warns `unionBags` src_warns `unionBags` listToBag occ_warns, - occ_fm, export_fn) + occ_fm, (export_fn, module_dotdots)) - }) >>= \ (rn_module, imp_mods, errs_so_far, warns_so_far, occ_fm, export_fn) -> + }) >>= \ (rn_module, imp_mods, errs_so_far, warns_so_far, occ_fm, export_stuff) -> if not (isEmptyBag errs_so_far) then 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 ... +-- _scc_ "preRnIfaces" let -- split up all names that occurred in the source; between -- those that are defined therein and those merely mentioned. @@ -189,16 +196,16 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) = [{-no Prelude.hi, no point looking-}] | otherwise = [ name_fn (mkWiredInName u orig ExportAll) - | (orig@(OrigName mod str), (u, name_fn)) <- fmToList b_keys, - str `notElem` [ SLIT("main"), SLIT("mainPrimIO")] ] + | (orig@(OrigName mod str), (u, name_fn)) <- fmToList builtinKeysMap ] in -- ASSERT (isEmptyBag orig_occ_dups) (if (isEmptyBag orig_occ_dups) then \x->x else pprTrace "orig_occ_dups:" (ppAboves [ ppCat [ppr PprDebug m, ppr PprDebug n, ppr PprDebug o] | (m,n,o) <- bagToList orig_occ_dups])) $ ASSERT (isEmptyBag orig_def_dups) +-- _scc_ "rnIfaces" rnIfaces iface_cache imp_mods us3 orig_def_env orig_occ_env - rn_module (must_haves ++ imports_used) >>= + rn_module (must_haves {-initMustHaves-} ++ imports_used) >>= \ (rn_module_with_imports, final_env, (implicit_val_fm, implicit_tc_fm), usage_stuff, @@ -207,7 +214,7 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) return (rn_module_with_imports, final_env, imp_mods, - export_fn, + export_stuff, usage_stuff, errs_so_far `unionBags` iface_errs, warns_so_far `unionBags` iface_warns) @@ -216,6 +223,17 @@ renameModule us input@(HsModule modname _ _ imports _ _ _ _ _ _ _ _ _ _) (us1, us') = splitUniqSupply us (us2, us3) = splitUniqSupply us' + +initMustHaves :: [RnName] + -- things we *must* find declarations for, because the + -- compiler may eventually make reference to them (e.g., + -- class Eq) +initMustHaves + | opt_NoImplicitPrelude + = [{-no Prelude.hi, no point looking-}] + | otherwise + = [ name_fn (mkWiredInName u orig ExportAll) + | (orig@(OrigName mod str), (u, name_fn)) <- fmToList builtinKeysMap ] \end{code} \begin{code} diff --git a/ghc/compiler/rename/RnBinds.lhs b/ghc/compiler/rename/RnBinds.lhs index f1618ad2db..ac8dc51be0 100644 --- a/ghc/compiler/rename/RnBinds.lhs +++ b/ghc/compiler/rename/RnBinds.lhs @@ -15,8 +15,8 @@ module RnBinds ( rnTopBinds, rnMethodBinds, rnBinds, - FreeVars(..), - DefinedVars(..) + SYN_IE(FreeVars), + SYN_IE(DefinedVars) ) where IMP_Ubiq() @@ -32,7 +32,7 @@ import RnExpr ( rnMatch, rnGRHSsAndBinds, rnPat, checkPrecMatch ) import CmdLineOpts ( opt_SigsRequired ) import Digraph ( stronglyConnComp ) import ErrUtils ( addErrLoc, addShortErrLocLine ) -import Name ( RdrName ) +import Name ( getLocalName, RdrName ) import Maybes ( catMaybes ) import PprStyle--ToDo:rm import Pretty @@ -524,7 +524,7 @@ rnBindSigs is_toplev binder_occnames sigs -- Discard unbound ones we've already complained about, so we -- complain about duplicate ones. - (goodies, dups) = removeDups compare (filter not_unbound sigs') + (goodies, dups) = removeDups compare (filter (\ x -> not_unbound x && not_main x) sigs') in mapRn (addErrRn . dupSigDeclErr) dups `thenRn_` @@ -598,7 +598,7 @@ rnBindSigs is_toplev binder_occnames sigs lookupValue v `thenRn` \ new_v -> returnRn (Just (MagicUnfoldingSig new_v str src_loc)) - not_unbound :: RenamedSig -> Bool + not_unbound, not_main :: RenamedSig -> Bool not_unbound (Sig n _ _ _) = not (isRnUnbound n) not_unbound (SpecSig n _ _ _) = not (isRnUnbound n) @@ -606,6 +606,10 @@ rnBindSigs is_toplev binder_occnames sigs not_unbound (DeforestSig n _) = not (isRnUnbound n) not_unbound (MagicUnfoldingSig n _ _) = not (isRnUnbound n) + not_main (Sig n _ _ _) = let str = getLocalName n in + not (str == SLIT("main") || str == SLIT("mainPrimIO")) + not_main _ = True + ------------------------------------- sig_free :: [RdrNameSig] -> RdrName -> Maybe RdrName -- Return "Just x" if "x" has no type signature in diff --git a/ghc/compiler/rename/RnIfaces.lhs b/ghc/compiler/rename/RnIfaces.lhs index 51366dbcf7..f805e312e9 100644 --- a/ghc/compiler/rename/RnIfaces.lhs +++ b/ghc/compiler/rename/RnIfaces.lhs @@ -50,7 +50,7 @@ import Name ( origName, moduleOf, nameOf, qualToOrigName, OrigName(..), isLexCon, RdrName(..), Name{-instance NamedThing-} ) import PprStyle -- ToDo:rm import Outputable -- ToDo:rm -import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames) ) +import PrelInfo ( builtinNameMaps, builtinKeysMap, builtinTcNamesMap, SYN_IE(BuiltinNames) ) import Pretty import UniqFM ( emptyUFM ) import UniqSupply ( splitUniqSupply ) @@ -81,9 +81,7 @@ data IfaceCache initIfaceCache mod hi_files = newVar (emptyFM,emptyFM,hi_files) ST_THEN \ iface_var -> - return (IfaceCache mod b_names iface_var) - where - b_names = case builtinNameInfo of (b_names,_,_) -> b_names + return (IfaceCache mod builtinNameMaps iface_var) \end{code} ********************************************************* @@ -749,19 +747,9 @@ rnIfaceInstStuff iface_cache@(IfaceCache _ _ iface_var) modname us occ_env done_ Just _ -> True Nothing -> -- maybe it's builtin let orig = qualToOrigName nm in - case (lookupFM b_tc_names orig) of + case (lookupFM builtinTcNamesMap orig) of Just _ -> True - Nothing -> maybeToBool (lookupFM b_keys orig) - - (b_tc_names, b_keys) -- pretty UGLY ... - = case builtinNameInfo of ((_,builtin_tcs),b_keys,_) -> (builtin_tcs,b_keys) -{- - ppr_insts insts - = ppAboves (map ppr_inst insts) - where - ppr_inst (InstSig c t _ inst_decl) - = ppCat [ppr PprDebug c, ppr PprDebug t, ppr PprDebug inst_decl] --} + Nothing -> maybeToBool (lookupFM builtinKeysMap orig) \end{code} \begin{code} @@ -877,7 +865,7 @@ ifaceLookupWiredErr msg n sty = ppBesides [ppPStr SLIT("Why am I looking up a wired-in "), ppStr msg, ppChar ':', ppr sty n] badIfaceLookupErr msg name decl sty - = ppBesides [ppPStr SLIT("Expected a "), ppStr msg, ppPStr SLIT(" declaration, but got this: ???")] + = ppBesides [ppPStr SLIT("Expected a "), ppStr msg, ppStr " declaration, but got this: ???"] ifaceIoErr io_msg rn sty = ppBesides [io_msg sty, ppStr "; looking for: ", ppr sty rn] diff --git a/ghc/compiler/rename/RnMonad.lhs b/ghc/compiler/rename/RnMonad.lhs index e6b7c93dd2..0f668bf06b 100644 --- a/ghc/compiler/rename/RnMonad.lhs +++ b/ghc/compiler/rename/RnMonad.lhs @@ -57,7 +57,7 @@ import Name ( SYN_IE(Module), RdrName(..), isQual, OrigName(..), Name, mkLocalName, mkImplicitName, getOccName, pprNonSym ) -import PrelInfo ( builtinNameInfo, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) +import PrelInfo ( builtinNameMaps, builtinKeysMap, SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import PrelMods ( pRELUDE ) import PprStyle{-ToDo:rm-} import Outputable{-ToDo:rm-} @@ -127,8 +127,7 @@ initRn source mod env us do_rn mode = if source then RnSource occ_var else - case builtinNameInfo of { (wiredin_fm, key_fm, _) -> - RnIface wiredin_fm key_fm imp_var } + RnIface builtinNameMaps builtinKeysMap imp_var rn_down = RnDown () mod mkUnknownSrcLoc mode env us_var errs_var in diff --git a/ghc/compiler/rename/RnNames.lhs b/ghc/compiler/rename/RnNames.lhs index b94dd7fb3a..7598489424 100644 --- a/ghc/compiler/rename/RnNames.lhs +++ b/ghc/compiler/rename/RnNames.lhs @@ -21,14 +21,14 @@ import RnHsSyn import RnMonad import RnIfaces ( IfaceCache, cachedIface, cachedDecl, CachingResult(..) ) -import RnUtils ( SYN_IE(RnEnv), emptyRnEnv, extendGlobalRnEnv, - lubExportFlag, qualNameErr, dupNamesErr +import RnUtils ( SYN_IE(RnEnv), emptyRnEnv, initRnEnv, extendGlobalRnEnv, + lubExportFlag, qualNameErr, dupNamesErr, pprRnEnv ) import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), ExportsMap(..), RdrIfaceInst ) import Bag ( emptyBag, unitBag, consBag, snocBag, unionBags, - unionManyBags, mapBag, filterBag, listToBag, bagToList ) + unionManyBags, mapBag, foldBag, filterBag, listToBag, bagToList ) 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-}, FiniteMap ) @@ -39,7 +39,7 @@ import Name ( RdrName(..), Name, isQual, mkTopLevName, mkWiredInName, origName, nameExportFlag, nameImportFlag, getLocalName, getSrcLoc, getImpLocs, moduleNamePair, pprNonSym, - isLexCon, ExportFlag(..), OrigName(..) + isLexCon, isLexSpecialSym, ExportFlag(..), OrigName(..) ) import PrelInfo ( SYN_IE(BuiltinNames), SYN_IE(BuiltinKeys) ) import PrelMods ( pRELUDE, gHC_BUILTINS, modulesWithBuiltins ) @@ -93,7 +93,7 @@ getGlobalNames iface_cache info us unqual_vals = map (\rn -> (Unqual (getLocalName rn), rn)) (bagToList src_vals) unqual_tcs = map (\rn -> (Unqual (getLocalName rn), rn)) (bagToList src_tcs) - (src_env, src_dups) = extendGlobalRnEnv emptyRnEnv unqual_vals unqual_tcs + (src_env, src_dups) = extendGlobalRnEnv initRnEnv unqual_vals unqual_tcs (all_env, imp_dups) = extendGlobalRnEnv src_env (bagToList imp_vals) (bagToList imp_tcs) -- remove dups of the same imported thing @@ -108,6 +108,9 @@ getGlobalNames iface_cache info us all_errs = src_errs `unionBags` imp_errs `unionBags` listToBag dup_errs all_warns = src_warns `unionBags` imp_warns in +-- pprTrace "initRnEnv:" (pprRnEnv PprDebug initRnEnv) $ +-- pprTrace "src_env:" (pprRnEnv PprDebug src_env) $ +-- pprTrace "all_env:" (pprRnEnv PprDebug all_env) $ return (all_env, imp_mods, unqual_imps, imp_fixes, all_errs, all_warns) } \end{code} @@ -406,25 +409,19 @@ doImportDecls iface_cache g_info us src_imps imp_errs `unionBags` errs, imp_warns `unionBags` warns) where - the_imps = implicit_prel ++ src_imps - all_imps = implicit_qprel ++ the_imps + all_imps = implicit_prel ++ src_imps +-- all_imps = implicit_qprel ++ the_imps - implicit_qprel = ImportDecl gHC_BUILTINS True Nothing Nothing prel_loc - : (if opt_NoImplicitPrelude - then [{- no "import qualified Prelude" -}] - else [ImportDecl pRELUDE True Nothing Nothing prel_loc]) + explicit_prelude_imp + = not (null [ () | (ImportDecl mod qual _ _ _) <- src_imps, mod == pRELUDE ]) - explicit_prelude_imp = not (null [ () | (ImportDecl mod qual _ _ _) <- src_imps, - mod == pRELUDE ]) - - implicit_prel = ImportDecl gHC_BUILTINS False Nothing Nothing prel_loc - : (if explicit_prelude_imp || opt_NoImplicitPrelude - then [{- no "import Prelude" -}] - else [ImportDecl pRELUDE False Nothing Nothing prel_loc]) + implicit_prel | opt_NoImplicitPrelude = [] + | explicit_prelude_imp = [ImportDecl pRELUDE True Nothing Nothing prel_loc] + | otherwise = [ImportDecl pRELUDE False Nothing Nothing prel_loc] prel_loc = mkBuiltinSrcLoc - (uniq_imps, imp_dups) = removeDups cmp_mod the_imps + (uniq_imps, imp_dups) = removeDups cmp_mod all_imps cmp_mod (ImportDecl m1 _ _ _ _) (ImportDecl m2 _ _ _ _) = cmpPString m1 m2 qprel_imps = [ imp | imp@(ImportDecl mod True Nothing _ _) <- src_imps, @@ -443,7 +440,7 @@ doImportDecls iface_cache g_info us src_imps where has_same_mod (_,ImportDecl mod2 _ _ _ _) = mod == mod2 - imp_mods = [ mod | ImportDecl mod _ _ _ _ <- uniq_imps, mod /= gHC_BUILTINS ] + imp_mods = [ mod | ImportDecl mod _ _ _ _ <- uniq_imps ] imp_warns = listToBag (map dupImportWarn imp_dups) `unionBags` @@ -513,17 +510,14 @@ doImport :: IfaceCache Bag (RnName,(ExportFlag,Bag SrcLoc))) -- import flags and src locs doImport iface_cache info us (ImportDecl mod qual maybe_as maybe_spec src_loc) - = let - (b_vals, b_tcs, maybe_spec') = getBuiltins info mod maybe_spec -- NB: a no-op ToDo:rm - in - (if mod == gHC_BUILTINS then - return (Succeeded (panic "doImport:GHC fake import!"), - \ iface -> ([], [], emptyBag)) - else - --pprTrace "doImport:" (ppPStr mod) $ - cachedIface iface_cache False SLIT("doImport") mod >>= \ maybe_iface -> - return (maybe_iface, \ iface -> getOrigIEs iface maybe_spec') - ) >>= \ (maybe_iface, do_ies) -> + = --let + -- (b_vals, b_tcs, maybe_spec') + -- = (emptyBag, emptyBag, maybe_spec) + --in + --pprTrace "doImport:" (ppPStr mod) $ + cachedIface iface_cache False SLIT("doImport") mod >>= \ maybe_iface -> + return (maybe_iface, \ iface -> getOrigIEs iface maybe_spec) + >>= \ (maybe_iface, do_ies) -> case maybe_iface of Failed err -> @@ -538,15 +532,14 @@ doImport iface_cache info us (ImportDecl mod qual maybe_as maybe_spec src_loc) accumulate (map (checkOrigIE iface_cache) chk_ies) >>= \ chk_errs_warns -> let - final_vals = mapBag fst_occ b_vals `unionBags` mapBag pair_occ ie_vals - final_tcs = mapBag fst_occ b_tcs `unionBags` mapBag pair_occ ie_tcs + fold_ies = foldBag unionBags pair_occ emptyBag + + final_vals = {-OLD:mapBag fst_occ b_vals `unionBags`-} fold_ies ie_vals + final_tcs = {-OLD:mapBag fst_occ b_tcs `unionBags`-} fold_ies ie_tcs final_vals_list = bagToList final_vals in - (if mod == gHC_BUILTINS then - return [ (Nothing, emptyBag) | _ <- final_vals_list ] - else - accumulate (map (getFixityDecl iface_cache . snd) final_vals_list) - ) >>= \ fix_maybes_errs -> + accumulate (map (getFixityDecl iface_cache . snd) final_vals_list) + >>= \ fix_maybes_errs -> let (chk_errs, chk_warns) = unzip chk_errs_warns (fix_maybes, fix_errs) = unzip fix_maybes_errs @@ -575,13 +568,23 @@ doImport iface_cache info us (ImportDecl mod qual maybe_as maybe_spec src_loc) fst_occ :: (FAST_STRING, RnName) -> (RdrName, RnName) fst_occ (str, rn) = (mk_occ str, rn) - pair_occ :: RnName -> (RdrName, RnName) - pair_occ rn = (mk_occ (getLocalName rn), rn) + pair_occ :: RnName -> Bag (RdrName, RnName) + pair_occ rn + = let + str = getLocalName rn + qual_bag = unitBag (Qual as_mod str, rn) + in + if qual + then qual_bag + else qual_bag -- the qualified name is *also* visible + `snocBag` (Unqual str, rn) + pair_as :: RnName -> (Module, RnName) pair_as rn = (as_mod, rn) ----------------------------- +{- getBuiltins :: ImportNameInfo -> Module -> Maybe (Bool, [RdrNameIE]) @@ -591,10 +594,9 @@ getBuiltins :: ImportNameInfo ) getBuiltins _ modname maybe_spec ---OLD: | modname `notElem` modulesWithBuiltins +-- | modname `notElem` modulesWithBuiltins = (emptyBag, emptyBag, maybe_spec) -{- getBuiltins (((b_val_names,b_tc_names),_,_,_),_,_,_) modname maybe_spec = case maybe_spec of Nothing -> (all_vals, all_tcs, Nothing) @@ -677,13 +679,18 @@ getOrigIEs (ParsedIface _ _ _ _ _ _ exps _ _ _ _ _ _) (Just (False, ies)) -- imp mkAllIE :: (OrigName, ExportFlag) -> IE OrigName mkAllIE (orig,ExportAbs) - = ASSERT(isLexCon (nameOf orig)) + = --ASSERT(isLexCon (nameOf orig)) + -- the ASSERT is correct, but it is too easy to + -- trigger when writing .hi files by hand (e.g. + -- when hackily breaking a module loop) IEThingAbs orig mkAllIE (orig, ExportAll) - | isLexCon (nameOf orig) + | isLexCon name_orig || isLexSpecialSym name_orig = IEThingAll orig | otherwise = IEVar orig + where + name_orig = nameOf orig ------------ lookupIEs :: ExportsMap @@ -761,11 +768,13 @@ doOrigIE iface_cache info mod src_loc us ie 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 + avoided_fn (Just (Left rn@(WiredInId _))) -- 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) + avoided_fn (Just (Right rn@(WiredInTyCon tc))) + -- a builtin tc brought into scope; we also must bring its + -- data constructors into scope + = --pprTrace "avoided:Right:" (ppr PprDebug rn) $ + (listToBag [WiredInId dc | dc <- tyConDataCons tc], unitBag rn, emptyBag, emptyBag, emptyBag) ------------------------- checkOrigIE :: IfaceCache @@ -810,11 +819,13 @@ with_decl :: IfaceCache -> IO something with_decl iface_cache n do_avoid do_err do_decl - = cachedDecl iface_cache (isLexCon (nameOf n)) n >>= \ maybe_decl -> + = cachedDecl iface_cache (isLexCon n_name || isLexSpecialSym n_name) n >>= \ maybe_decl -> case maybe_decl of CachingAvoided info -> return (do_avoid info) CachingFail err -> return (do_err err) CachingHit decl -> return (do_decl decl) + where + n_name = nameOf n ------------- getFixityDecl :: IfaceCache diff --git a/ghc/compiler/rename/RnSource.lhs b/ghc/compiler/rename/RnSource.lhs index 3829b51be6..277862f3bf 100644 --- a/ghc/compiler/rename/RnSource.lhs +++ b/ghc/compiler/rename/RnSource.lhs @@ -25,7 +25,7 @@ import Class ( derivableClassKeys ) import CmdLineOpts ( opt_CompilingGhcInternals ) import ErrUtils ( addErrLoc, addShortErrLocLine, addShortWarnLocLine ) import FiniteMap ( emptyFM, lookupFM, addListToFM_C ) -import Id ( GenId{-instance NamedThing-} ) +import Id ( isDataCon, GenId{-instance NamedThing-} ) import ListSetOps ( unionLists, minusList ) import Maybes ( maybeToBool, catMaybes ) import Name ( isLocallyDefined, isLexVarId, getLocalName, ExportFlag(..), @@ -63,6 +63,8 @@ rnSource :: [Module] -- imported modules -> RdrNameHsModule -> RnM s (RenamedHsModule, Name -> ExportFlag, -- export info + ([(Name, ExportFlag)], -- export module X stuff + [(Name, ExportFlag)]), Bag (RnName, RdrName)) -- occurrence info rnSource imp_mods unqual_imps imp_fixes @@ -73,7 +75,7 @@ rnSource imp_mods unqual_imps imp_fixes = pushSrcLocRn src_loc $ - rnExports (mod:imp_mods) unqual_imps exports `thenRn` \ exported_fn -> + rnExports (mod:imp_mods) unqual_imps exports `thenRn` \ (exported_fn, module_dotdots) -> rnFixes fixes `thenRn` \ src_fixes -> let all_fixes = src_fixes ++ bagToList imp_fixes @@ -99,7 +101,7 @@ rnSource imp_mods unqual_imps imp_fixes new_ty_decls new_specdata_sigs new_class_decls new_inst_decls new_specinst_sigs new_defaults new_binds [] src_loc, - exported_fn, + exported_fn, module_dotdots, occ_info ) where @@ -118,10 +120,15 @@ rnSource imp_mods unqual_imps imp_fixes rnExports :: [Module] -> Bag (Module,RnName) -> Maybe [RdrNameIE] - -> RnM s (Name -> ExportFlag) + -> RnM s (Name -> ExportFlag, -- main export-flag fun + ([(Name,ExportFlag)], -- info about "module X" exports + [(Name,ExportFlag)]) + ) rnExports mods unqual_imps Nothing - = returnRn (\n -> if isLocallyDefined n then ExportAll else NotExported) + = returnRn (\n -> if isLocallyDefined n then ExportAll else NotExported + , ([], []) + ) rnExports mods unqual_imps (Just exps) = getModuleRn `thenRn` \ this_mod -> @@ -141,7 +148,7 @@ rnExports mods unqual_imps (Just exps) (uniq_mods, dup_mods) = removeDups cmpPString exp_mods (expmods_this, expmods_imps) = partition (== this_mod) uniq_mods - -- Get names for module This_Mod export + -- Get names for "module This_Mod" export (this_tcs, this_vals) = if null expmods_this then ([], []) @@ -155,16 +162,23 @@ rnExports mods unqual_imps (Just exps) (unqual_tcs, unqual_vals) = partition (isRnTyConOrClass.snd) (bagToList unqual_imps) get_mod_names mod - = (tcs, vals, empty_mod) + = --pprTrace "get_mod_names" (ppAboves [ppPStr mod, interpp'SP PprDebug (map fst tcs), interpp'SP PprDebug (map fst vals)]) $ + (tcs, vals, empty_mod) where tcs = [(getName rn, nameImportFlag (getName rn)) | (mod',rn) <- unqual_tcs, mod == mod'] vals = [(getName rn, nameImportFlag (getName rn)) - | (mod',rn) <- unqual_vals, mod == mod'] + | (mod',rn) <- unqual_vals, mod == mod', fun_looking rn] empty_mod = if null tcs && null vals then Just mod else Nothing + -- fun_looking: must avoid class ops and data constructors + -- and record fieldnames + fun_looking (RnName _) = True + fun_looking (WiredInId i) = not (isDataCon i) + fun_looking _ = False + -- Build finite map of exported names to export flag tc_map0 = addListToUFM_C lub_expflag emptyUFM (map pair_fst tc_names) tc_map1 = addListToUFM_C lub_expflag tc_map0 (map pair_fst mod_tcs) @@ -198,8 +212,17 @@ rnExports mods unqual_imps (Just exps) mapRn (addWarnRn . emptyModExportWarn src_loc) empty_mods `thenRn_` mapRn (addErrRn . dupLocalsExportErr src_loc) dup_tc_locals `thenRn_` mapRn (addErrRn . dupLocalsExportErr src_loc) dup_val_locals `thenRn_` - returnRn exp_fn + returnRn (exp_fn, (mod_vals, mod_tcs)) + +------------------------------------ +-- rename an "IE" in the export list +rnIE :: [Module] -- this module and all the (directly?) imported modules + -> RdrNameIE + -> RnM s ( + Maybe Module, -- Just m => a "module X" export item + (Bag (Name, ExportFlag), -- Exported tycons/classes + Bag (Name, ExportFlag))) -- Exported values rnIE mods (IEVar name) = lookupValue name `thenRn` \ rn -> @@ -249,7 +272,7 @@ rnIE mods (IEThingAll name) warnAndContinueRn (unitBag (n, ExportAbs), emptyBag) (synAllExportErr False{-warning-} rn src_loc) - checkIEAll rn = pprTrace "rnIE:IEAll:panic? ToDo?:" (ppr PprDebug rn) $ + checkIEAll rn = --pprTrace "rnIE:IEAll:panic? ToDo?:" (ppr PprDebug rn) $ returnRn (emptyBag, emptyBag) exp_all n = (n, ExportAll) @@ -622,7 +645,7 @@ rnFixes fixities rn_fixity_pieces mk_fixity name i fix = getRnEnv `thenRn` \ env -> case lookupGlobalRnEnv env name of - Just res | isLocallyDefined res || opt_CompilingGhcInternals + 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. diff --git a/ghc/compiler/rename/RnUtils.lhs b/ghc/compiler/rename/RnUtils.lhs index 781aa8bcf8..acf64f71ac 100644 --- a/ghc/compiler/rename/RnUtils.lhs +++ b/ghc/compiler/rename/RnUtils.lhs @@ -9,28 +9,31 @@ module RnUtils ( SYN_IE(RnEnv), SYN_IE(QualNames), SYN_IE(UnqualNames), SYN_IE(ScopeStack), - emptyRnEnv, extendGlobalRnEnv, extendLocalRnEnv, + emptyRnEnv, initRnEnv, extendGlobalRnEnv, extendLocalRnEnv, lookupRnEnv, lookupGlobalRnEnv, lookupTcRnEnv, getLocalsFromRnEnv, lubExportFlag, qualNameErr, - dupNamesErr + dupNamesErr, + pprRnEnv -- debugging only ) where IMP_Ubiq(){-uitous-} IMPORT_1_3(List(partition)) import Bag ( Bag, emptyBag, snocBag, unionBags ) -import CmdLineOpts ( opt_CompilingGhcInternals ) +import CmdLineOpts ( opt_GlasgowExts ) import ErrUtils ( addShortErrLocLine ) -import FiniteMap ( FiniteMap, emptyFM, isEmptyFM, - lookupFM, addListToFM, addToFM, eltsFM ) +import FiniteMap ( emptyFM, isEmptyFM, fmToList, listToFM, keysFM, + lookupFM, addListToFM, addToFM, eltsFM, FiniteMap ) import Maybes ( maybeToBool ) import Name ( RdrName(..), ExportFlag(..), isQual, pprNonSym, getLocalName, isLocallyDefined ) import PprStyle ( PprStyle(..) ) +import PrelInfo ( builtinValNamesMap, builtinTcNamesMap ) +import PrelMods ( gHC_BUILTINS ) import Pretty import RnHsSyn ( RnName ) import Util ( assertPanic ) @@ -53,6 +56,7 @@ type UnqualNames = FiniteMap FAST_STRING RnName type ScopeStack = FiniteMap FAST_STRING RnName emptyRnEnv :: RnEnv +initRnEnv :: RnEnv extendGlobalRnEnv :: RnEnv -> [(RdrName,RnName)] -> [(RdrName,RnName)] -> (RnEnv, Bag (RdrName, RnName, RnName)) extendLocalRnEnv :: Bool -> RnEnv -> [RnName] -> (RnEnv, [RnName]) @@ -80,8 +84,28 @@ seperately. It optionally reports any shadowed names. \begin{code} -emptyRnEnv - = ((emptyFM, emptyFM, emptyFM, emptyFM), emptyFM) +emptyRnEnv = ((emptyFM, emptyFM, emptyFM, emptyFM), emptyFM) + + -- an emptyRnEnv is empty; the initRnEnv may have + -- primitive names already in it (both unqual and qual), + -- and quals for all the other wired-in dudes. + +initRnEnv + = if (not opt_GlasgowExts) then + emptyRnEnv + else + ((listToFM qual, listToFM unqual, listToFM tc_qual, listToFM tc_unqual), emptyFM) + where + qual = [ ((n,m), rn) | (OrigName m n, rn) <- fmToList builtinValNamesMap ] + tc_qual = [ ((n,m), rn) | (OrigName m n, rn) <- fmToList builtinTcNamesMap ] + + builtin_qual = filter (\ ((_,m),_) -> m == gHC_BUILTINS) qual + builtin_tc_qual = filter (\ ((_,m),_) -> m == gHC_BUILTINS) tc_qual + + unqual = map (\ ((n,_),rn) -> (n,rn)) builtin_qual + tc_unqual = map (\ ((n,_),rn) -> (n,rn)) builtin_tc_qual + +----------------- extendGlobalRnEnv ((qual, unqual, tc_qual, tc_unqual), stack) val_list tc_list = ASSERT(isEmptyFM stack) @@ -129,16 +153,13 @@ extendLocalRnEnv report_shadows (global, stack) new_local ext_dups = if maybeToBool (lookupFM stack str) then name:dups else dups +\end{code} - +\begin{code} 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_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) + Unqual str -> lookup stack str (lookupFM unqual str) + Qual mod str -> lookupFM qual (str,mod) where lookup fm thing do_on_fail = case lookupFM fm thing of @@ -148,25 +169,12 @@ lookupRnEnv ((qual, unqual, _, _), stack) rdr lookupGlobalRnEnv ((qual, unqual, _, _), _) rdr = case rdr of Unqual str -> lookupFM unqual str - Qual mod str -> case (lookupFM qual (str,mod)) of - Just xx -> Just xx - Nothing -> if not opt_CompilingGhcInternals then - Nothing - else -- "[]" may have turned into "Prelude.[]" and - -- we are actually compiling "data [] a = ..."; - -- maybe the right thing is to get "Prelude.[]" - -- into the "qual" table... - lookupFM unqual str + Qual mod str -> lookupFM qual (str,mod) lookupTcRnEnv ((_, _, tc_qual, tc_unqual), _) rdr = case rdr of 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_CompilingGhcInternals then - Nothing - else - lookupFM tc_unqual str + Qual mod str -> lookupFM tc_qual (str,mod) getLocalsFromRnEnv ((_, vals, _, tcs), _) = (filter isLocallyDefined (eltsFM vals), @@ -209,5 +217,20 @@ dupNamesErr descriptor ((name1,locn1) : dup_things) sty = addShortErrLocLine locn (\ sty -> ppBesides [ppStr "here was another declaration of `", pprNonSym sty name, ppStr "'" ]) sty -\end{code} +----------------- +pprRnEnv :: PprStyle -> RnEnv -> Pretty + +pprRnEnv sty ((qual, unqual, tc_qual, tc_unqual), stack) + = ppAboves [ ppStr "Stack:" + , ppCat (map ppPStr (keysFM stack)) + , ppStr "Val qual:" + , ppAboves [ppBesides [ppPStr m, ppChar '.', ppPStr n] | (n,m) <- keysFM qual] + , ppStr "Val unqual:" + , ppCat (map ppPStr (keysFM unqual)) + , ppStr "Tc qual:" + , ppAboves [ppBesides [ppPStr m, ppChar '.', ppPStr n] | (n,m) <- keysFM tc_qual] + , ppStr "Tc unqual:" + , ppCat (map ppPStr (keysFM tc_unqual)) + ] +\end{code} |