Migrate cvs diff from fptools-assoc branch
[ghc-hetmet.git] / compiler / typecheck / TcRnMonad.lhs
index f515334..0b5e4fc 100644 (file)
@@ -50,7 +50,8 @@ import Outputable
 import UniqSupply      ( UniqSupply, mkSplitUniqSupply, uniqFromSupply, splitUniqSupply )
 import UniqFM          ( unitUFM )
 import Unique          ( Unique )
 import UniqSupply      ( UniqSupply, mkSplitUniqSupply, uniqFromSupply, splitUniqSupply )
 import UniqFM          ( unitUFM )
 import Unique          ( Unique )
-import DynFlags                ( DynFlags(..), DynFlag(..), dopt, dopt_set, GhcMode )
+import DynFlags                ( DynFlags(..), DynFlag(..), dopt, dopt_set,
+                         dopt_unset, GhcMode ) 
 import StaticFlags     ( opt_PprStyle_Debug )
 import Bag             ( snocBag, unionBags )
 import Panic           ( showException )
 import StaticFlags     ( opt_PprStyle_Debug )
 import Bag             ( snocBag, unionBags )
 import Panic           ( showException )
@@ -268,6 +269,10 @@ setOptM :: DynFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
 setOptM flag = updEnv (\ env@(Env { env_top = top }) ->
                         env { env_top = top { hsc_dflags = dopt_set (hsc_dflags top) flag}} )
 
 setOptM flag = updEnv (\ env@(Env { env_top = top }) ->
                         env { env_top = top { hsc_dflags = dopt_set (hsc_dflags top) flag}} )
 
+unsetOptM :: DynFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
+unsetOptM flag = updEnv (\ env@(Env { env_top = top }) ->
+                        env { env_top = top { hsc_dflags = dopt_unset (hsc_dflags top) flag}} )
+
 ifOptM :: DynFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()    -- Do it flag is true
 ifOptM flag thing_inside = do { b <- doptM flag; 
                                if b then thing_inside else return () }
 ifOptM :: DynFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()    -- Do it flag is true
 ifOptM flag thing_inside = do { b <- doptM flag; 
                                if b then thing_inside else return () }
@@ -323,17 +328,28 @@ getEpsAndHpt = do { env <- getTopEnv; eps <- readMutVar (hsc_EPS env)
 
 \begin{code}
 newUnique :: TcRnIf gbl lcl Unique
 
 \begin{code}
 newUnique :: TcRnIf gbl lcl Unique
-newUnique = do { us <- newUniqueSupply ; 
-                return (uniqFromSupply us) }
+newUnique
+ = do { env <- getEnv ;
+       let { u_var = env_us env } ;
+       us <- readMutVar u_var ;
+        case splitUniqSupply us of { (us1,_) -> do {
+       writeMutVar u_var us1 ;
+       return $! uniqFromSupply us }}}
+   -- NOTE 1: we strictly split the supply, to avoid the possibility of leaving
+   -- a chain of unevaluated supplies behind.
+   -- NOTE 2: we use the uniq in the supply from the MutVar directly, and
+   -- throw away one half of the new split supply.  This is safe because this
+   -- is the only place we use that unique.  Using the other half of the split
+   -- supply is safer, but slower.
 
 newUniqueSupply :: TcRnIf gbl lcl UniqSupply
 newUniqueSupply
  = do { env <- getEnv ;
        let { u_var = env_us env } ;
        us <- readMutVar u_var ;
 
 newUniqueSupply :: TcRnIf gbl lcl UniqSupply
 newUniqueSupply
  = do { env <- getEnv ;
        let { u_var = env_us env } ;
        us <- readMutVar u_var ;
-       let { (us1, us2) = splitUniqSupply us } ;
+        case splitUniqSupply us of { (us1,us2) -> do {
        writeMutVar u_var us1 ;
        writeMutVar u_var us1 ;
-       return us2 }
+       return us2 }}}
 
 newLocalName :: Name -> TcRnIf gbl lcl Name
 newLocalName name      -- Make a clone
 
 newLocalName :: Name -> TcRnIf gbl lcl Name
 newLocalName name      -- Make a clone