Add -fno-implicit-import-qualified (#2452)
authorSimon Marlow <marlowsd@gmail.com>
Tue, 5 Aug 2008 15:17:30 +0000 (15:17 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Tue, 5 Aug 2008 15:17:30 +0000 (15:17 +0000)
The flag is off by default, but GHCi turns it on (in Main.hs).  For
GHCi it can be overriden on the command-line or using :set.

compiler/main/DynFlags.hs
compiler/rename/RnEnv.lhs
docs/users_guide/flags.xml
docs/users_guide/ghci.xml
ghc/Main.hs

index c3700bf..5031ded 100644 (file)
@@ -278,6 +278,7 @@ data DynFlag
    | Opt_RunCPSZ
    | Opt_ConvertToZipCfgAndBack
    | Opt_AutoLinkPackages
+   | Opt_ImplicitImportQualified
 
    -- keeping stuff
    | Opt_KeepHiDiffs
@@ -1532,7 +1533,8 @@ fFlags = [
   ( "allow-incoherent-instances",       Opt_IncoherentInstances,
     deprecatedForLanguage "IncoherentInstances" ),
   ( "gen-manifest",                     Opt_GenManifest, const Supported ),
-  ( "embed-manifest",                   Opt_EmbedManifest, const Supported )
+  ( "embed-manifest",                   Opt_EmbedManifest, const Supported ),
+  ( "implicit-import-qualified",        Opt_ImplicitImportQualified, const Supported )
   ]
 
 supportedLanguages :: [String]
index 94c90ac..63db61c 100644 (file)
@@ -359,23 +359,27 @@ lookupGlobalOccRn rdr_name
   = lookupImportedName rdr_name        
 
   | otherwise
-  =    -- First look up the name in the normal environment.
-   lookupGreRn_maybe rdr_name          `thenM` \ mb_gre ->
+  = do
+       -- First look up the name in the normal environment.
+   mb_gre <- lookupGreRn_maybe rdr_name
    case mb_gre of {
        Just gre -> returnM (gre_name gre) ;
-       Nothing   -> 
+       Nothing   -> do
 
        -- We allow qualified names on the command line to refer to 
        --  *any* name exported by any module in scope, just as if 
        -- there was an "import qualified M" declaration for every 
        -- module.
-   getModule           `thenM` \ mod ->
-   if isQual rdr_name && mod == iNTERACTIVE then       
-                                       -- This test is not expensive,
-       lookupQualifiedName rdr_name    -- and only happens for failed lookups
-   else        do
+   allow_qual <- doptM Opt_ImplicitImportQualified
+   mod <- getModule
+               -- This test is not expensive,
+               -- and only happens for failed lookups
+   if isQual rdr_name && allow_qual && mod == iNTERACTIVE
+      then lookupQualifiedName rdr_name
+      else do 
         traceRn $ text "lookupGlobalOccRn"
-       unboundName rdr_name }
+        unboundName rdr_name
+  }
 
 lookupImportedName :: RdrName -> TcRnIf m n Name
 -- Lookup the occurrence of an imported name
index 23c1b2b..ef57f13 100644 (file)
              <entry>dynamic</entry>
              <entry>-</entry>
            </row>
+           <row>
+             <entry><option>-fno-implicit-import-qualified</option></entry>
+             <entry><link linkend="ghci-import-qualified">Turn off
+             implicit qualified import of everything in GHCi</link></entry>
+             <entry>dynamic</entry>
+             <entry>-</entry>
+           </row>
 
          </tbody>
        </tgroup>
index 299b1e5..1f20df4 100644 (file)
@@ -650,13 +650,14 @@ Prelude IO>
             loaded</literal>&rdquo;.</para>
       </sect3>
 
-      <sect3>
+      <sect3 id="ghci-import-qualified">
        <title>Qualified names</title>
 
        <para>To make life slightly easier, the GHCi prompt also
         behaves as if there is an implicit <literal>import
         qualified</literal> declaration for every module in every
-        package, and every module currently loaded into GHCi.</para>
+        package, and every module currently loaded into GHCi.  This
+          behaviour can be disabled with the flag <option>-fno-implicit-import-qualified</option><indexterm><primary><option>-fno-implicit-import-qualified</option></primary></indexterm>.</para>
       </sect3>
 
       <sect3>
index a2c2fd1..840f843 100644 (file)
@@ -125,9 +125,16 @@ main =
                                         _other   -> 1
                        }
 
+      -- turn on -fimplicit-import-qualified for GHCi now, so that it
+      -- can be overriden from the command-line
+      dflags1a | DoInteractive <- cli_mode = imp_qual_enabled
+               | DoEval _      <- cli_mode = imp_qual_enabled
+               | otherwise                 = dflags1
+        where imp_qual_enabled = dflags1 `dopt_set` Opt_ImplicitImportQualified
+
        -- The rest of the arguments are "dynamic"
        -- Leftover ones are presumably files
-  (dflags2, fileish_args, dynamicFlagWarnings) <- GHC.parseDynamicFlags dflags1 argv3
+  (dflags2, fileish_args, dynamicFlagWarnings) <- GHC.parseDynamicFlags dflags1a argv3
 
   let flagWarnings = staticFlagWarnings
                   ++ modeFlagWarnings