Use System.FilePath
[ghc-hetmet.git] / compiler / main / DynFlags.hs
index 359ea39..7d692ec 100644 (file)
@@ -93,6 +93,7 @@ import Util           ( split )
 #endif
 
 import Data.Char
+import System.FilePath
 import System.IO        ( hPutStrLn, stderr )
 
 -- -----------------------------------------------------------------------------
@@ -774,6 +775,10 @@ runWhen :: Bool -> CoreToDo -> CoreToDo
 runWhen True  do_this = do_this
 runWhen False do_this = CoreDoNothing
 
+runMaybe :: Maybe a -> (a -> CoreToDo) -> CoreToDo
+runMaybe (Just x) f = f x
+runMaybe Nothing  _ = CoreDoNothing
+
 getCoreToDo :: DynFlags -> [CoreToDo]
 getCoreToDo dflags
   | Just todo <- coreToDo dflags = todo -- set explicitly by user
@@ -790,8 +795,7 @@ getCoreToDo dflags
     rule_check    = ruleCheck dflags
     vectorisation = dopt Opt_Vectorise dflags
 
-    maybe_rule_check phase | Just s <- rule_check = CoreDoRuleCheck phase s
-                           | otherwise            = CoreDoNothing
+    maybe_rule_check phase = runMaybe rule_check (CoreDoRuleCheck phase)
 
     simpl_phase phase iter = CoreDoPasses
                                [ CoreDoSimplify (SimplPhase phase) [
@@ -842,7 +846,7 @@ getCoreToDo dflags
 
         -- We run vectorisation here for now, but we might also try to run
         -- it later
-        runWhen vectorisation (CoreDoPasses [ CoreDoVectorisation, simpl_gently]),
+        runWhen vectorisation (CoreDoPasses [ CoreDoVectorisation, simpl_gently ]),
 
        -- Specialisation is best done before full laziness
        -- so that overloaded functions have all their dictionary lambdas manifest
@@ -1332,7 +1336,10 @@ xFlags = [
 
 impliedFlags :: [(DynFlag, [DynFlag])]
 impliedFlags = [
-  ( Opt_GADTs, [Opt_RelaxedPolyRec] )  -- We want type-sig variables to be completely rigid for GADTs
+   ( Opt_GADTs,              [Opt_RelaxedPolyRec] )    -- We want type-sig variables to 
+                                                       --      be completely rigid for GADTs
+ , ( Opt_ScopedTypeVariables, [Opt_RelaxedPolyRec] )   -- Ditto for scoped type variables; see
+                                                       --      Note [Scoped tyvars] in TcBinds
   ]
 
 glasgowExtsFlags = [
@@ -1567,32 +1574,28 @@ setTmpDir :: FilePath -> DynFlags -> DynFlags
 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
   where
 #if !defined(mingw32_HOST_OS)
-     canonicalise p = normalisePath p
+     canonicalise p = normalise p
 #else
-       -- Canonicalisation of temp path under win32 is a bit more
-       -- involved: (a) strip trailing slash, 
-       --           (b) normalise slashes
-       --           (c) just in case, if there is a prefix /cygdrive/x/, change to x:
-       -- 
-     canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
-
-        -- if we're operating under cygwin, and TMP/TEMP is of
-       -- the form "/cygdrive/drive/path", translate this to
-       -- "drive:/path" (as GHC isn't a cygwin app and doesn't
-       -- understand /cygdrive paths.)
-     xltCygdrive path
-      | "/cygdrive/" `isPrefixOf` path = 
-         case drop (length "/cygdrive/") path of
-           drive:xs@('/':_) -> drive:':':xs
-           _ -> path
-      | otherwise = path
-
-        -- strip the trailing backslash (awful, but we only do this once).
-     removeTrailingSlash path = 
-       case last path of
-         '/'  -> init path
-         '\\' -> init path
-         _    -> path
+     -- Canonicalisation of temp path under win32 is a bit more
+     -- involved: (a) strip trailing slash,
+     --      (b) normalise slashes
+     --     (c) just in case, if there is a prefix /cygdrive/x/, change to x:
+     canonicalise path = removeTrailingSlash $ normalise $ xltCygdrive path
+
+     -- if we're operating under cygwin, and TMP/TEMP is of
+     -- the form "/cygdrive/drive/path", translate this to
+     -- "drive:/path" (as GHC isn't a cygwin app and doesn't
+     -- understand /cygdrive paths.)
+     cygdrivePrefix = [pathSeparator] ++ "/cygdrive/" ++ [pathSeparator]
+     xltCygdrive path = case maybePrefixMatch cygdrivePrefix path of
+                        Just (drive:sep:xs))
+                         | isPathSeparator sep -> drive:':':pathSeparator:xs
+                        _ -> path
+
+     -- strip the trailing backslash (awful, but we only do this once).
+     removeTrailingSlash path
+      | isPathSeparator (last path) = init path
+      | othwerwise                  = path
 #endif
 
 -----------------------------------------------------------------------------