diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2015-02-11 10:55:10 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2015-02-11 11:18:24 +0000 |
commit | 6ff3db92140e3ac8cbda50d1a4aab976350ac8c4 (patch) | |
tree | 2560bc260b80fd79f6eeff258119a0e27dbebd7f /compiler | |
parent | 3568bf3fe76b95208f650f356a0668113838d842 (diff) | |
download | haskell-6ff3db92140e3ac8cbda50d1a4aab976350ac8c4.tar.gz |
nameIsLocalOrFrom should include interactive modules
The provoking cause was Trac #10019, but it revealed that nameIsLocalOrFrom
should really include all interactive modules (ones from the 'interactive'
package). Previously we had some ad-hoc 'isInteractiveModule' tests with
some (but not all) the calls to nameIsLocalOrFrom.
See the new comments with Name.nameIsLocalOrFrom.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/basicTypes/Name.hs | 31 | ||||
-rw-r--r-- | compiler/iface/LoadIface.hs | 16 | ||||
-rw-r--r-- | compiler/rename/RnEnv.hs | 6 | ||||
-rw-r--r-- | compiler/typecheck/TcDeriv.hs | 4 | ||||
-rw-r--r-- | compiler/typecheck/TcRnDriver.hs | 18 |
5 files changed, 51 insertions, 24 deletions
diff --git a/compiler/basicTypes/Name.hs b/compiler/basicTypes/Name.hs index 3b0da643ba..ab476dbc9b 100644 --- a/compiler/basicTypes/Name.hs +++ b/compiler/basicTypes/Name.hs @@ -189,7 +189,6 @@ nameSrcSpan name = n_loc name ************************************************************************ -} -nameIsLocalOrFrom :: Module -> Name -> Bool isInternalName :: Name -> Bool isExternalName :: Name -> Bool isSystemName :: Name -> Bool @@ -218,9 +217,32 @@ nameModule_maybe (Name { n_sort = External mod}) = Just mod nameModule_maybe (Name { n_sort = WiredIn mod _ _}) = Just mod nameModule_maybe _ = Nothing +nameIsLocalOrFrom :: Module -> Name -> Bool +-- ^ Returns True if the name is +-- (a) Internal +-- (b) External but from the specified module +-- (c) External but from the 'interactive' package +-- +-- The key idea is that +-- False means: the entity is defined in some other module +-- you can find the details (type, fixity, instances) +-- in some interface file +-- those details will be stored in the EPT or HPT +-- +-- True means: the entity is defined in this module or earlier in +-- the GHCi session +-- you can find details (type, fixity, instances) in the +-- TcGblEnv or TcLclEnv +-- +-- The isInteractiveModule part is because successive interactions of a GCHi session +-- each give rise to a fresh module (Ghci1, Ghci2, etc), but they all come +-- from the magic 'interactive' package; and all the details are kept in the +-- TcLclEnv, TcGblEnv, NOT in the HPT or EPT. +-- See Note [The interactive package] in HscTypes + nameIsLocalOrFrom from name - | isExternalName name = from == nameModule name - | otherwise = True + | Just mod <- nameModule_maybe name = from == mod || isInteractiveModule mod + | otherwise = True isTyVarName :: Name -> Bool isTyVarName name = isTvOcc (nameOccName name) @@ -334,7 +356,8 @@ localiseName n = n { n_sort = Internal } -- |Create a localised variant of a name. -- -- If the name is external, encode the original's module name to disambiguate. --- +-- SPJ says: this looks like a rather odd-looking function; but it seems to +-- be used only during vectorisation, so I'm not going to worry mkLocalisedOccName :: Module -> (Maybe String -> OccName -> OccName) -> Name -> OccName mkLocalisedOccName this_mod mk_occ name = mk_occ origin (nameOccName name) where diff --git a/compiler/iface/LoadIface.hs b/compiler/iface/LoadIface.hs index 51f6bae20e..169e929ae4 100644 --- a/compiler/iface/LoadIface.hs +++ b/compiler/iface/LoadIface.hs @@ -320,17 +320,15 @@ loadModuleInterfaces doc mods load mod = loadSysInterface (doc <+> parens (ppr mod)) mod -- | Loads the interface for a given Name. +-- Should only be called for an imported name; +-- otherwise loadSysInterface may not find the interface loadInterfaceForName :: SDoc -> Name -> TcRn ModIface loadInterfaceForName doc name - = do { - when debugIsOn $ do - -- Should not be called with a name from the module being compiled - { this_mod <- getModule - ; MASSERT2( not (nameIsLocalOrFrom this_mod name), ppr name <+> parens doc ) - } - ; ASSERT2( isExternalName name, ppr name ) - initIfaceTcRn $ loadSysInterface doc (nameModule name) - } + = do { when debugIsOn $ -- Check pre-condition + do { this_mod <- getModule + ; MASSERT2( not (nameIsLocalOrFrom this_mod name), ppr name <+> parens doc ) } + ; ASSERT2( isExternalName name, ppr name ) + initIfaceTcRn $ loadSysInterface doc (nameModule name) } -- | Loads the interface for a given Module. loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface diff --git a/compiler/rename/RnEnv.hs b/compiler/rename/RnEnv.hs index b6f12a7dfc..580f0b9d3d 100644 --- a/compiler/rename/RnEnv.hs +++ b/compiler/rename/RnEnv.hs @@ -1277,9 +1277,9 @@ lookupFixityRn name Nothing -> do { this_mod <- getModule - ; if nameIsLocalOrFrom this_mod name || isInteractiveModule (nameModule name) - -- Interactive modules are all in the fixity env, - -- and don't have entries in the HPT + ; if nameIsLocalOrFrom this_mod name + -- Local (and interactive) names are all in the + -- fixity env, and don't have entries in the HPT then return defaultFixity else lookup_imported } } } where diff --git a/compiler/typecheck/TcDeriv.hs b/compiler/typecheck/TcDeriv.hs index 3d980e2327..90737209e6 100644 --- a/compiler/typecheck/TcDeriv.hs +++ b/compiler/typecheck/TcDeriv.hs @@ -31,7 +31,7 @@ import TcHsType import TcMType import TcSimplify import LoadIface( loadInterfaceForName ) -import Module( getModule, isInteractiveModule ) +import Module( getModule ) import RnNames( extendGlobalRdrEnvRn ) import RnBinds @@ -2101,7 +2101,7 @@ getDataConFixityFun :: TyCon -> TcM (Name -> Fixity) -- c.f. RnEnv.lookupFixity, and Trac #9830 getDataConFixityFun tc = do { this_mod <- getModule - ; if nameIsLocalOrFrom this_mod name || isInteractiveModule (nameModule name) + ; if nameIsLocalOrFrom this_mod name then do { fix_env <- getFixityEnv ; return (lookupFixity fix_env) } else do { iface <- loadInterfaceForName doc name diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs index 8f94d6ca67..c3b16ca367 100644 --- a/compiler/typecheck/TcRnDriver.hs +++ b/compiler/typecheck/TcRnDriver.hs @@ -1998,18 +1998,24 @@ loadUnqualIfaces hsc_env ictxt where this_pkg = thisPackage (hsc_dflags hsc_env) - unqual_mods = [ mod + unqual_mods = [ nameModule name | gre <- globalRdrEnvElts (ic_rn_gbl_env ictxt) , let name = gre_name gre - , not (isInternalName name) - , let mod = nameModule name - , not (modulePackageKey mod == this_pkg || isInteractiveModule mod) - -- Don't attempt to load an interface for stuff - -- from the command line, or from the home package + , from_external_package name , isTcOcc (nameOccName name) -- Types and classes only , unQualOK gre ] -- In scope unqualified doc = ptext (sLit "Need interface for module whose export(s) are in scope unqualified") + from_external_package name -- True <=> the Name comes from some other package + -- (not the home package, not the interactive package) + | Just mod <- nameModule_maybe name + , modulePackageKey mod /= this_pkg -- Not the home package + , not (isInteractiveModule mod) -- Not the 'interactive' package + = True + | otherwise + = False + + {- ************************************************************************ * * |