[project @ 2001-02-06 17:31:00 by simonmar]
authorsimonmar <unknown>
Tue, 6 Feb 2001 17:31:00 +0000 (17:31 +0000)
committersimonmar <unknown>
Tue, 6 Feb 2001 17:31:00 +0000 (17:31 +0000)
Qualified names on the command line may now refer to any exported
entity from any module, not just entities from the "original" defining
module.

eg. "IO.hFlush IO.stdout" now works.

There's still a problem in that home interfaces may be demand-loaded
if they're aren't already in memory, which is wrong (you can refer to
a module which isn't loaded, causing things to fall over at link
time).

ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnHiFiles.hi-boot-5 [new file with mode: 0644]

index b835791..fc262ed 100644 (file)
@@ -8,6 +8,9 @@ module RnEnv where              -- Export everything
 
 #include "HsVersions.h"
 
+import {-# SOURCE #-} RnHiFiles
+
+import HscTypes                ( ModIface(..) )
 import HsSyn
 import RdrHsSyn                ( RdrNameIE )
 import RdrName         ( RdrName, rdrNameModule, rdrNameOcc, isQual, isUnqual, isOrig,
@@ -27,7 +30,9 @@ import Name           ( Name,
 import Name            ( extendNameEnv_C, plusNameEnv_C, nameEnvElts )
 import NameSet
 import OccName         ( OccName, occNameUserString, occNameFlavour )
-import Module          ( ModuleName, moduleName, mkVanillaModule, mkSysModuleNameFS, moduleNameFS )
+import Module          ( ModuleName, moduleName, mkVanillaModule, 
+                         mkSysModuleNameFS, moduleNameFS,
+                         WhereFrom(..) )
 import FiniteMap
 import UniqSupply
 import SrcLoc          ( SrcLoc, noSrcLoc )
@@ -238,9 +243,23 @@ lookupGlobalOccRn rdr_name
         | otherwise -> 
                case lookupRdrEnv global_env rdr_name of
                       Just _  -> lookupSrcName global_env rdr_name
-                      Nothing -> newGlobalName (rdrNameModule rdr_name)
-                                               (rdrNameOcc rdr_name)
-
+                      Nothing -> lookupQualifiedName rdr_name
+
+-- a qualified name on the command line can refer to any module at all: we
+-- try to load the interface if we don't already have it.
+lookupQualifiedName :: RdrName -> RnM d Name
+lookupQualifiedName rdr_name
+ = let 
+       mod = rdrNameModule rdr_name
+       occ = rdrNameOcc rdr_name
+   in
+   loadInterface (ppr rdr_name) mod ImportBySystem `thenRn` \ iface ->
+   case  [ name | (_,avails) <- mi_exports iface,
+          avail             <- avails,
+          name              <- availNames avail,
+          nameOccName name == occ ] of
+      (n:ns) -> ASSERT (null ns) returnRn n
+      _      -> failWithRn (mkUnboundName rdr_name) (unknownNameErr rdr_name)
 
 lookupSrcName :: GlobalRdrEnv -> RdrName -> RnM d Name
 -- NB: passed GlobalEnv explicitly, not necessarily in RnMS monad
diff --git a/ghc/compiler/rename/RnHiFiles.hi-boot-5 b/ghc/compiler/rename/RnHiFiles.hi-boot-5
new file mode 100644 (file)
index 0000000..98d4308
--- /dev/null
@@ -0,0 +1,3 @@
+__interface RnHiFiles 1 0 where
+__export RnHiFiles loadInterface;
+1 loadInterface :: __forall d => Outputable.SDoc -> Module.ModuleName -> Module.WhereFrom -> RnMonad.RnM d HscTypes.ModIface;