Massive patch for the first months work adding System FC to GHC #22
[ghc-hetmet.git] / compiler / main / DynFlags.hs
index 6c5bfd6..0a361a4 100644 (file)
@@ -1,3 +1,4 @@
+{-# OPTIONS -fno-warn-missing-fields #-}
 -----------------------------------------------------------------------------
 --
 -- Dynamic flags
@@ -49,16 +50,23 @@ module DynFlags (
 
 #include "HsVersions.h"
 
-import Module          ( Module, mkModule )
+import Module          ( Module, mkModuleName, mkModule )
+import PackageConfig
 import PrelNames       ( mAIN )
-import StaticFlags     ( opt_Static, opt_PIC, 
-                         WayName(..), v_Ways, v_Build_tag, v_RTS_Build_tag )
+#ifdef i386_TARGET_ARCH
+import StaticFlags     ( opt_Static )
+#endif
+import StaticFlags     ( opt_PIC, WayName(..), v_Ways, v_Build_tag,
+                         v_RTS_Build_tag )
 import {-# SOURCE #-} Packages (PackageState)
 import DriverPhases    ( Phase(..), phaseInputExt )
 import Config
 import CmdLineParser
+import Constants       ( mAX_CONTEXT_REDUCTION_DEPTH )
 import Panic           ( panic, GhcException(..) )
-import Util            ( notNull, splitLongestPrefix, split, normalisePath )
+import UniqFM           ( UniqFM )
+import Util            ( notNull, splitLongestPrefix, normalisePath )
+import Maybes          ( fromJust, orElse )
 import SrcLoc           ( SrcSpan )
 
 import DATA_IOREF      ( readIORef )
@@ -66,8 +74,10 @@ import EXCEPTION     ( throwDyn )
 import Monad           ( when )
 #ifdef mingw32_TARGET_OS
 import Data.List       ( isPrefixOf )
+#else
+import Util            ( split )
 #endif
-import Maybe           ( fromJust )
+
 import Char            ( isDigit, isUpper )
 import Outputable
 import System.IO        ( hPutStrLn, stderr )
@@ -145,10 +155,12 @@ data DynFlag
    | Opt_AllowUndecidableInstances
    | Opt_AllowIncoherentInstances
    | Opt_MonomorphismRestriction
+   | Opt_MonoPatBinds
+   | Opt_ExtendedDefaultRules          -- Use GHC's extended rules for defaulting
    | Opt_GlasgowExts
    | Opt_FFI
-   | Opt_PArr                         -- syntactic support for parallel arrays
-   | Opt_Arrows                               -- Arrow-notation syntax
+   | Opt_PArr                          -- Syntactic support for parallel arrays
+   | Opt_Arrows                                -- Arrow-notation syntax
    | Opt_TH
    | Opt_ImplicitParams
    | Opt_Generics
@@ -209,6 +221,9 @@ data DynFlags = DynFlags {
   importPaths          :: [FilePath],
   mainModIs            :: Module,
   mainFunIs            :: Maybe String,
+  ctxtStkDepth         :: Int,         -- Typechecker context stack depth
+
+  thisPackage          :: PackageId,
 
   -- ways
   wayNames             :: [WayName],   -- way flags from the cmd line
@@ -233,6 +248,9 @@ data DynFlags = DynFlags {
   cmdlineFrameworks    :: [String],    -- ditto
   tmpDir               :: String,      -- no trailing '/'
   
+  ghcUsagePath          :: FilePath,    -- Filled in by SysTools
+  ghciUsagePath         :: FilePath,    -- ditto
+
   -- options for particular phases
   opt_L                        :: [String],
   opt_P                        :: [String],
@@ -254,16 +272,23 @@ data DynFlags = DynFlags {
   pgm_a                        :: (String,[Option]),
   pgm_l                        :: (String,[Option]),
   pgm_dll              :: (String,[Option]),
+  pgm_T                 :: String,
+  pgm_sysman            :: String,
 
-  --  ** Package flags
+  --  Package flags
   extraPkgConfs                :: [FilePath],
+  topDir                :: FilePath,    -- filled in by SysTools
+  systemPackageConfig   :: FilePath,    -- ditto
        -- The -package-conf flags given on the command line, in the order
        -- they appeared.
 
   packageFlags         :: [PackageFlag],
        -- The -package and -hide-package flags from the command-line
 
-  --  ** Package state
+  -- Package state
+  -- NB. do not modify this field, it is calculated by 
+  -- Packages.initPackages and Packages.updatePackages.
+  pkgDatabase           :: Maybe (UniqFM InstalledPackageInfo),
   pkgState             :: PackageState,
 
   -- hsc dynamic flags
@@ -309,6 +334,7 @@ data PackageFlag
   = ExposePackage  String
   | HidePackage    String
   | IgnorePackage  String
+  deriving Eq
 
 defaultHscTarget
   | cGhcWithNativeCodeGen == "YES"     =  HscAsm
@@ -343,10 +369,9 @@ defaultDynFlags =
        importPaths             = ["."],
        mainModIs               = mAIN,
        mainFunIs               = Nothing,
-       
-       wayNames                = panic "ways",
-       buildTag                = panic "buildTag",
-       rtsBuildTag             = panic "rtsBuildTag",
+       ctxtStkDepth            = mAX_CONTEXT_REDUCTION_DEPTH,
+
+       thisPackage             = mainPackageId,
 
        objectDir               = Nothing,
        hiDir                   = Nothing,
@@ -374,24 +399,19 @@ defaultDynFlags =
        opt_dll                 = [],
        opt_dep                 = [],
        
-       pgm_L                   = panic "pgm_L",
-       pgm_P                   = panic "pgm_P",
-       pgm_F                   = panic "pgm_F",
-       pgm_c                   = panic "pgm_c",
-       pgm_m                   = panic "pgm_m",
-       pgm_s                   = panic "pgm_s",
-       pgm_a                   = panic "pgm_a",
-       pgm_l                   = panic "pgm_l",
-       pgm_dll                 = panic "pgm_mkdll",
-       
        extraPkgConfs           = [],
        packageFlags            = [],
-       pkgState                = panic "pkgState",
+        pkgDatabase             = Nothing,
+        pkgState                = panic "no package state yet: call GHC.setSessionDynFlags",
        
        flags = [ 
            Opt_RecompChecking,
            Opt_ReadUserPackageConf,
     
+           Opt_MonoPatBinds,   -- Experimentally, I'm making this non-standard
+                               -- behaviour the default, to see if anyone notices
+                               -- SLPJ July 06
+
            Opt_ImplicitPrelude,
            Opt_MonomorphismRestriction,
            Opt_Strictness,
@@ -789,7 +809,7 @@ dynamic_flags = [
   ,  ( "cpp"           , NoArg  (setDynFlag Opt_Cpp))
   ,  ( "F"             , NoArg  (setDynFlag Opt_Pp))
   ,  ( "#include"      , HasArg (addCmdlineHCInclude) )
-  ,  ( "v"             , OptPrefix (setVerbosity) )
+  ,  ( "v"             , OptIntSuffix setVerbosity )
 
         ------- Specific phases  --------------------------------------------
   ,  ( "pgmL"           , HasArg (upd . setPgmL) )  
@@ -859,7 +879,7 @@ dynamic_flags = [
         ------- Packages ----------------------------------------------------
   ,  ( "package-conf"   , HasArg extraPkgConf_ )
   ,  ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
-  ,  ( "package-name"   , HasArg ignorePackage ) -- for compatibility
+  ,  ( "package-name"   , HasArg setPackageName )
   ,  ( "package"        , HasArg exposePackage )
   ,  ( "hide-package"   , HasArg hidePackage )
   ,  ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
@@ -918,7 +938,7 @@ dynamic_flags = [
   ,  ( "dstg-lint",             NoArg (setDynFlag Opt_DoStgLinting))
   ,  ( "dcmm-lint",             NoArg (setDynFlag Opt_DoCmmLinting))
   ,  ( "dshow-passes",           NoArg (do unSetDynFlag Opt_RecompChecking
-                                          setVerbosity "2") )
+                                          setVerbosity (Just 2)) )
   ,  ( "dfaststring-stats",     NoArg (setDynFlag Opt_D_faststring_stats))
 
        ------ Machine dependant (-m<blah>) stuff ---------------------------
@@ -959,6 +979,9 @@ dynamic_flags = [
   ,  ( "fglasgow-exts",    NoArg (mapM_ setDynFlag   glasgowExtsFlags) )
   ,  ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
 
+  ,  ( "fcontext-stack"        , OptIntSuffix $ \mb_n -> upd $ \dfs -> 
+                         dfs{ ctxtStkDepth = mb_n `orElse` 3 })
+
        -- the rest of the -f* and -fno-* flags
   ,  ( "fno-",                 PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
   ,  ( "f",            PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
@@ -992,6 +1015,8 @@ fFlags = [
   ( "scoped-type-variables",           Opt_ScopedTypeVariables ),
   ( "bang-patterns",                   Opt_BangPatterns ),
   ( "monomorphism-restriction",                Opt_MonomorphismRestriction ),
+  ( "mono-pat-binds",                  Opt_MonoPatBinds ),
+  ( "extended-default-rules",          Opt_ExtendedDefaultRules ),
   ( "implicit-params",                 Opt_ImplicitParams ),
   ( "allow-overlapping-instances",     Opt_AllowOverlappingInstances ),
   ( "allow-undecidable-instances",     Opt_AllowUndecidableInstances ),
@@ -1017,8 +1042,7 @@ glasgowExtsFlags = [
   Opt_GlasgowExts, 
   Opt_FFI, 
   Opt_ImplicitParams, 
-  Opt_ScopedTypeVariables,
-  Opt_BangPatterns ]
+  Opt_ScopedTypeVariables ]
 
 isFFlag f = f `elem` (map fst fFlags)
 getFFlag f = fromJust (lookup f fFlags)
@@ -1052,10 +1076,8 @@ setDumpFlag dump_flag
        -- Whenver we -ddump, switch off the recompilation checker,
        -- else you don't see the dump!
 
-setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
-setVerbosity n 
-  | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
-  | otherwise     = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
+setVerbosity :: Maybe Int -> DynP ()
+setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
 
 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes =  a : cmdlineHcIncludes s})
 
@@ -1067,6 +1089,13 @@ hidePackage p =
   upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
 ignorePackage p = 
   upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
+setPackageName p
+  | Nothing <- unpackPackageId pid
+  = throwDyn (CmdLineError ("cannot parse \'" ++ p ++ "\' as a package identifier"))
+  | otherwise
+  = upd (\s -> s{ thisPackage = pid })
+  where
+        pid = stringToPackageId p
 
 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags 
 -- (-fvia-C, -fasm, -filx respectively).
@@ -1090,10 +1119,10 @@ setMainIs :: String -> DynP ()
 setMainIs arg
   | not (null main_fn)         -- The arg looked like "Foo.baz"
   = upd $ \d -> d{ mainFunIs = Just main_fn,
-                  mainModIs = mkModule main_mod }
+                  mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
 
   | isUpper (head main_mod)    -- The arg looked like "Foo"
-  = upd $ \d -> d{ mainModIs = mkModule main_mod }
+  = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
   
   | otherwise                  -- The arg looked like "baz"
   = upd $ \d -> d{ mainFunIs = Just main_mod }