
New patches:

[Fix #1537 (Generalize typechecking of do notation for rebindable syntax)
Pepe Iborra <mnislaih@gmail.com>**20071013185110
   The typechecker didn't handle rebindable syntax for do-notation
       in full generality. The problem is that it assumes too much about
       the type of bind, which can be rebinded to something completely 
       different by the user. 
       
       It is convenient to assume the type of  monadic bind 
       in order to give user friendly error messages, so this patch
       uses the assumption as long as the NoImplicitPrelude flag is not
       enabled. 
 
   MERGE TO STABLE
 
] {
hunk ./compiler/deSugar/DsExpr.lhs 595
-    				  result_ty (cantFailMatchResult body)
+    				  (exprType body) (cantFailMatchResult body)
hunk ./compiler/typecheck/TcMatches.lhs 19
-		   tcDoStmt, tcMDoStmt, tcGuardStmt
+		   tcDoStmtSimple, tcMDoStmt, tcGuardStmt
hunk ./compiler/typecheck/TcMatches.lhs 37
+import Type
hunk ./compiler/typecheck/TcMatches.lhs 45
+import DynFlags
+
+import Control.Monad ( liftM )
hunk ./compiler/typecheck/TcMatches.lhs 244
-tcDoStmts DoExpr stmts body res_ty
-  = do	{ ((m_ty, elt_ty), coi) <- boxySplitAppTy res_ty
-	; let res_ty' = mkAppTy m_ty elt_ty	-- The boxySplit consumes res_ty
-	; (stmts', body') <- tcStmts DoExpr (tcDoStmt m_ty) stmts 
-				     (emptyRefinement, res_ty') $
-			     tcBody body
-	; return $ mkHsWrapCoI coi (HsDo DoExpr stmts' body' res_ty') }
+tcDoStmts DoExpr stmts body res_ty = do
+  rebind_syntax <- not `liftM` doptM Opt_ImplicitPrelude
+  if not rebind_syntax 
+    then tcDoStmtsExprSimple stmts body res_ty
+    else do
+        ((m_ty, elt_ty), coi) <- boxySplitAppTy res_ty
+	let res_ty' = mkAppTy m_ty elt_ty	-- The boxySplit consumes res_ty	
+            reft_res_ty = (emptyRefinement, res_ty')
+	(stmts', body') <- tcStmts DoExpr tcDoStmt stmts reft_res_ty $ 
+                           tcBody body
+	return $ mkHsWrapCoI coi (HsDo DoExpr stmts' body' res_ty')
hunk ./compiler/typecheck/TcMatches.lhs 274
+
+tcDoStmtsExprSimple stmts body res_ty
+  = do	{ ((m_ty, elt_ty), coi) <- boxySplitAppTy res_ty
+	; let res_ty' = mkAppTy m_ty elt_ty	-- The boxySplit consumes res_ty
+	; (stmts', body') <- tcStmts DoExpr (tcDoStmtSimple m_ty) stmts 
+				     (emptyRefinement, res_ty') $
+			     tcBody body
+	; return $ mkHsWrapCoI coi (HsDo DoExpr stmts' body' res_ty') }
+
hunk ./compiler/typecheck/TcMatches.lhs 420
-tcDoStmt :: TcType		-- Monad type,  m
+tcDoStmtSimple :: TcType		-- Monad type,  m
hunk ./compiler/typecheck/TcMatches.lhs 423
-tcDoStmt m_ty ctxt (BindStmt pat rhs bind_op fail_op) reft_res_ty@(_,res_ty) thing_inside
+tcDoStmtSimple m_ty ctxt (BindStmt pat rhs bind_op fail_op) reft_res_ty@(_,res_ty) thing_inside
hunk ./compiler/typecheck/TcMatches.lhs 447
-tcDoStmt m_ty ctxt (ExprStmt rhs then_op _) reft_res_ty@(_,res_ty) thing_inside
+tcDoStmtSimple m_ty ctxt (ExprStmt rhs then_op _) reft_res_ty@(_,res_ty) thing_inside
hunk ./compiler/typecheck/TcMatches.lhs 449
-	  a_ty <- newFlexiTyVarTy liftedTypeKind
+	  a_ty     <- newFlexiTyVarTy liftedTypeKind
hunk ./compiler/typecheck/TcMatches.lhs 452
+	; rhs'     <- tcPolyExpr rhs rhs_ty
+	; then_op' <- tcSyntaxOp DoOrigin then_op then_ty
+	; thing    <- thing_inside reft_res_ty
+	; return (ExprStmt rhs' then_op' rhs_ty, thing) }
+
+tcDoStmtSimple m_ty ctxt stmt res_ty thing_inside
+  = pprPanic "tcDoStmt: unexpected Stmt" (ppr stmt)
+
+
+tcDoStmt :: TcStmtChecker
+
+-- tcDoStmt: the stmt at the lhs of a bind, i.e. (rhs >>= \pat -> thing) :: res_ty
+tcDoStmt ctxt (BindStmt pat rhs bind_op fail_op) (reft,res_ty) thing_inside
+  = do	{ 
+		-- We should use type *inference* for the RHS computations, becuase of GADTs. 
+		-- 	do { pat <- rhs; <rest> }
+		-- is rather like
+		--	case rhs of { pat -> <rest> }
+		-- We do inference on rhs, so that information about its type can be refined
+		-- when type-checking the pattern. 
+          m1_ty          <- newFlexiTyVarTy (liftedTypeKind `mkFunTy` liftedTypeKind) 
+        ; (rhs', pat_ty) <- withBox liftedTypeKind $ \pat_ty ->
+                            tcMonoExpr rhs (mkAppTy m1_ty pat_ty)
+        ; let rhs_ty      = mkAppTy m1_ty pat_ty
+        ; m2_ty          <- newFlexiTyVarTy (liftedTypeKind `mkFunTy` liftedTypeKind)
+        ; b_ty           <- newFlexiTyVarTy liftedTypeKind
+        ; let thing_ty    = mkAppTy m2_ty b_ty
+	; (pat', thing)  <- tcLamPat pat pat_ty (reft, thing_ty)
+                                              thing_inside
+
+	-- Deal with rebindable syntax; (>>=) :: m1 pat_ty -> (pat_ty -> m2 b) -> m3 c
+	; let bind_ty = mkFunTys [rhs_ty,
+				  mkFunTy pat_ty thing_ty]
+                                  res_ty
+	; bind_op' <- tcSyntaxOp DoOrigin bind_op bind_ty
+		-- If (but only if) the pattern can fail, 
+		-- typecheck the 'fail' operator
+	; fail_op' <- if isIrrefutableHsPat pat'
+		      then return noSyntaxExpr
+		      else tcSyntaxOp DoOrigin fail_op (mkFunTy stringTy thing_ty)
+	; return (BindStmt pat' rhs' bind_op' fail_op', thing) }
+-- (rhs >> thing) :: res_ty
+tcDoStmt ctxt (ExprStmt rhs then_op _) (reft,res_ty) thing_inside
+  = do	{ 	-- Deal with rebindable syntax; (>>) :: m1 a -> m2 b -> m3 c
+	; a_ty  <- newFlexiTyVarTy liftedTypeKind
+	; b_ty  <- newFlexiTyVarTy liftedTypeKind
+	; m1_ty  <- newFlexiTyVarTy (mkFunTy liftedTypeKind liftedTypeKind)
+	; m2_ty  <- newFlexiTyVarTy (mkFunTy liftedTypeKind liftedTypeKind)
+	; let then_ty  = mkFunTys [rhs_ty, thing_ty] res_ty
+              thing_ty = mkAppTy m2_ty b_ty
+              rhs_ty   = mkAppTy m1_ty a_ty
hunk ./compiler/typecheck/TcMatches.lhs 504
-	; rhs' <- tcPolyExpr rhs rhs_ty
-	; thing <- thing_inside reft_res_ty
+	; rhs'     <- tcPolyExpr rhs rhs_ty
+	; thing    <- thing_inside (reft, thing_ty)
hunk ./compiler/typecheck/TcMatches.lhs 508
-tcDoStmt m_ty ctxt stmt res_ty thing_inside
+tcDoStmt ctxt stmt res_ty thing_inside
hunk ./compiler/typecheck/TcRnDriver.lhs 1047
-	    tc_io_stmts stmts = tcStmts DoExpr (tcDoStmt io_ty) stmts 
+	    tc_io_stmts stmts = tcStmts DoExpr (tcDoStmtSimple io_ty) stmts 
}

Context:

[Fix DoCon: Another try at getting extractResults right
simonpj@microsoft.com**20071012162325
 
 For some reason TcSimplify.extractResults is quite difficult to get right.
 This is another attempt; finally I think I have it.
 
 Strangely enough, it's only Sergey's DoCon program that shows up the
 bug, which manifested as a failure in the Simplifier
 
         lookupRecBndr $dGCDRing{v a1Lz} [lid]
 
 But it was due to extractResults producing multiple bindings for
 the same dictionary.
 
 Please merge this to the stable branch (after previous patches to
 TcSimplify though).
 
 
] 
[mention what SCC stands for
Simon Marlow <simonmar@microsoft.com>**20071011135736] 
[Add a proper write barrier for MVars
Simon Marlow <simonmar@microsoft.com>**20071011135505
 Previously MVars were always on the mutable list of the old
 generation, which meant every MVar was visited during every minor GC.
 With lots of MVars hanging around, this gets expensive.  We addressed
 this problem for MUT_VARs (aka IORefs) a while ago, the solution is to
 use a traditional GC write-barrier when the object is modified.  This
 patch does the same thing for MVars.
 
 TVars are still done the old way, they could probably benefit from the
 same treatment too.
] 
[we need to #include "Stg.h" first, we can't rely on GHC to inject it
Simon Marlow <simonmar@microsoft.com>**20071010153244
 This fixes the unreg build, and in general building the RTS code
 via-C. I'm not sure at what stage this was broken, but I think it
 was working accidentally before.
] 
[Fix Trac #1680; check for unboxed tuples in TcType.marshalableTyCon
simonpj@microsoft.com**20071011123426] 
[Fix Trac #1759: do not let ticks get in the way of spotting trivially-true guards
simonpj@microsoft.com**20071010164731
 
 GHC spots that an 'otherwise' guard is true, and uses that knowledge to 
 avoid reporting spurious missing-pattern or overlaps with -Wall.
 
 The HPC ticks were disguising the 'otherwise', which led to this failure.
 Now we check.  The key change is defining DsGRHSs.isTrueLHsExpr.
 
 Test is ds062
 
 
] 
[Fix Trac #1755; check for stage errors in TH quoted Names
simonpj@microsoft.com**20071010150250
 
 There are a number of situations in which you aren't allowed to use
 a quoted Name in a TH program, such as
 	\x -> 'x
 But we weren't checking for that!  Now we are.
 
 Merge to stable branch.
 
 Test is TH_qname.
 
 
] 
[checkWellStaged: reverse comparsion (no change in semantics), plus some comments
simonpj@microsoft.com**20071010124013] 
[Add traceTc in tcSimplifyDefault
simonpj@microsoft.com**20071010123933] 
[Improve pretty-printing of splices in HsSyn
simonpj@microsoft.com**20071010123726] 
[Fix Trac #1678; be more careful about catching and reporting exceptions in spliced TH monadic computations
simonpj@microsoft.com**20071010145705
 
 Many of the new lines are comments to explain the slightly-convoluted
 in which exceptions get propagated out of the Q monad.
 
 This fixes Trac 1679; test is TH_runIO (as well as the exising TH_fail).
 
 Please merge
 
 
] 
[Comments only
simonpj@microsoft.com**20071010145646] 
[FIX BUILD (when compiling base via C): declare n_capabilities
Simon Marlow <simonmar@microsoft.com>**20071010103704] 
[GHCi: use non-updatable thunks for breakpoints
Simon Marlow <simonmar@microsoft.com>**20071010093241
 The extra safe points introduced for breakpoints were previously
 compiled as normal updatable thunks, but they are guaranteed
 single-entry, so we can use non-updatable thunks here.  This restores
 the tail-call property where it was lost in some cases (although stack
 squeezing probably often recovered it), and should improve
 performance.
] 
[FIX #1681: withBreakAction had too large a scope in runStmt
Simon Marlow <simonmar@microsoft.com>**20071010085820] 
[tiny refactoring
Simon Marlow <simonmar@microsoft.com>**20071009145002] 
[small reworking of the loop-breaker-choosing algorithm
Simon Marlow <simonmar@microsoft.com>**20071009145305
 Previously inline candidates were given higher preference as
 non-loop-breakers than constructor applications, but the reason for
 this was that making a wrapper into a loop-breaker is to be avoided at
 all costs.  This patch refines the algorithm slightly so that wrappers
 are explicitly avoided by giving them a much higher score, and other
 inline candidates are given lower scores than constructor
 applications.
 
 This makes almost zero difference to a complete nofib run, so it
 amounts to just a tidyup.
] 
[Fix warnings when build w/o readline
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20071010101840] 
[Update documentation for win32 DLL linking
Clemens Fruhwirth <clemens@endorphin.org>**20071010074415] 
[FIX: tidy up TcSimplify following equality constraints additions
simonpj@microsoft.com**20071010093334
 
 The combination of "type refinement" for GADTs and the new equality
 constraints has made TcSimplify rather complicated.  And wrong:
 it generated bogus code for cholewo-eval.
 
 This patch is still far from entirely satisfactory.  There are
 too many places where invariants are unclear, and the code is 
 still a bit of a mess.  But I believe it's better, and it passes
 the regression tests!  So I think it's good enough for the 6.8 release.
 
 Please merge.
 
 The main changes are:
 
 - get rid of extractLocalResults (which was always suspicious)
 
 - instead, treat the 'refinement' along with 'givens', by 
   adding a field to RedEnv, red_reft which travels with red_givens
 
 - I also reworked extractResults a bit, which looked wrong to me
   This entailed changing the Given constructor in Avail to take
   an Inst rather than a TcId
 
 
] 
[Improve pretty-printing for HsSyn
simonpj@microsoft.com**20071010093058] 
[Fix Trac #1746: make rule-matching work properly with Cast expressions
simonpj@microsoft.com**20070929104406
 
 The Cast case of the rule-matcher was simply wrong.
 
 This patch fixes it; see Trac #1746.
 
 I also fixed the rule generation in SpecConstr to generate a wild-card
 for the cast expression, which we don't want to match on.  This makes
 the rule more widely applicable; it wasn't the cause of the bug.
 
] 
[Small comment only
simonpj@microsoft.com**20070929104309] 
[export n_capabilities, see #1733
Simon Marlow <simonmar@microsoft.com>**20071009142701] 
[FIX #1743, create a fresh unique for each Id we bind at a breakpoint
Simon Marlow <simonmar@microsoft.com>**20071009142554] 
[remove vestiges of way 'u' (see #1008)
Simon Marlow <simonmar@microsoft.com>**20071009130942] 
[also call initMutex on every task->lock, see #1391
Simon Marlow <simonmar@microsoft.com>**20071009122409] 
[remove the "-unreg" flag and the unregisterised way, see #1008
Simon Marlow <simonmar@microsoft.com>**20071009122338] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071009105138] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071003170005] 
[refactoring only: use the parameterised InstalledPackageInfo
Simon Marlow <simonmar@microsoft.com>**20071003163536
 This required moving PackageId from PackageConfig to Module
] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071003174016] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071003173448] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071003173202] 
[warning removal
Simon Marlow <simonmar@microsoft.com>**20071003172715] 
[remove most warnings
Simon Marlow <simonmar@microsoft.com>**20071003090804] 
[mkIfaceExports: sort the children of AvailTC
Simon Marlow <simonmar@microsoft.com>**20071002114917
 This fixes a problem with spurious recompilations: each time a module
 was recompiled, the order of the children would change, causing extra
 recompilation.
 
 MERGE TO STABLE
] 
[error message fix (#1758)
Simon Marlow <simonmar@microsoft.com>**20071008134958] 
[FIX validate for PPC Mac OS X - RegAllocStats.hs
Thorkil Naur <naur@post11.tele.dk>**20071005144105] 
[FIX validate for PPC Mac OS X - RegAllocLinear.hs
Thorkil Naur <naur@post11.tele.dk>**20071005143607] 
[FIX validate for PPC Mac OS X - Linker.c
Thorkil Naur <naur@post11.tele.dk>**20071005144908] 
[FIX validate for PPC Mac OS X - Evac.h
Thorkil Naur <naur@post11.tele.dk>**20071005144454] 
[FIX #1748: -main-is wasn't handling the case of a single hierarchical module
Simon Marlow <simonmar@microsoft.com>**20071008131305
 test case is driver062.5
] 
[FIX BUILD FD_SETSIZE signed
jochemberndsen@dse.nl**20070927132649
 On FreeBSD FD_SETSIZE is unsigned. Cast it to a signed int
 for portability.
] 
[FIX BUILD addDLL returns const char*
jochemberndsen@dse.nl**20070927132619
 addDLL returns const char*, not just a char*.
 Fix compiler warning
] 
[FIX BUILD `set -o igncr'-issue on FreeBSD
jochemberndsen@dse.nl**20070926203750
 `set -o igncr' does not work on non-cygwin-systems.
 Fail silently if this command does not work, instead
 of aborting the build.
 
] 
[comment-out "use vars" in 3 places (see #1739)
Simon Marlow <simonmar@microsoft.com>**20071008115740] 
[Change DOCOPTIONS pragma to DOC_OPTIONS
David Waern <davve@dtek.chalmers.se>**20071002143849
 
 MERGE TO STABLE
] 
[FIX: parsing of doc options
David Waern <davve@dtek.chalmers.se>**20071002143713
 
 Lexing of the doc options pragma was changed, but but no change was 
 made to the parser to reflect that. This patch fixes this problem.
 
 MERGE TO STABLE
] 
[FIX: add missing case to OccName.isSymOcc
David Waern <davve@dtek.chalmers.se>**20071002143459] 
[Remove warnings from WwLib
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20071002130736] 
[FIX: mkWWcpr takes open alg types into account
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20071002130407
 - This fixed the failures of GMapAssoc and GMapTop for optmising ways
 
 MERGE TO STABLE
] 
[FIX #1738: KPush rule of FC must take dataConEqTheta into account
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20071001154343
 
 MERGE TO STABLE
] 
[FIX #1729: Don't try to expand syn families with -XLiberalTypeSynonyms
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20070929122624
 
 MERGE TO STABLE
] 
[Some more traceTcs
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20070929121941] 
[FIX: Make boxy splitters aware of type families
Manuel M T Chakravarty <chak@cse.unsw.edu.au>**20070928225541
 
 MERGE TO STABLE
] 
[html_installed_root shouldn't contain $$pkgid
Ian Lynagh <igloo@earth.li>**20070927130427
 This actually didn't break anything, as the shell expanded $pkgid to the
 empty string, but it was still wrong.
] 
[Comments and debug output only
simonpj@microsoft.com**20070927110842] 
[further stub filename fix: I managed to break non-stubdir -fvia-C compilation
Simon Marlow <simonmar@microsoft.com>**20070927102539] 
[Finally, I managed to squash an infamous bug in :print
Pepe Iborra <mnislaih@gmail.com>**20070927151300
   
   It turns out the newtype handling code in :print
   was slipping non mutable Tyvars in the types reconstructed.
   The error message eventually produced was rather obscure:
   
   [src/Tp.hs:75:28-64] *MainTp> :p x
   *** Exception: No match in record selector Var.tcTyVarDetails
   [src/Tp.hs:75:28-64] *MainTp>
   
   Due to non mutable tyvars, unifyType was failing.
   A well placed assertion in the unifyType code would have made
    my life much easier.
   Which reminds me I should install a -ddump-* system in the 
   RTTI subsystem, or future hackers will run away in swearing.
 
 
 MERGE TO STABLE
 
] 
[Be a bit more flexible in terminal identification for do_bold
Pepe Iborra <mnislaih@gmail.com>**20070927141549
   
   In Os X for instance, by default we have TERM=xterm-color 
 
 MERGE TO STABLE
 
] 
[also acquire/release task->lock across fork()
Simon Marlow <simonmar@microsoft.com>**20070927091331
 further attempt to fix #1391 on MacOS
] 
[FIX -stubdir bug: the .hc file was #including the wrong _stub.h filename
Simon Marlow <simonmar@microsoft.com>**20070926134539
 Using -stubdir together with hierarchical modules, -fvia-C, and --make
 is essentially broken in 6.6.x.  Recently discovered by Cabal's use of
 -stubdir.
 
 Test cases: driver027/driver028 (I've updated them to use -fvia-C, in
 order to test for this bug).
] 
[Add STANDARD_OPTS to SRC_HC_OPTS in rts/Makefile so we get -I../includes for .cmm files
Ian Lynagh <igloo@earth.li>**20070926122637
 Patch from Clemens Fruhwirth
] 
[fix #1734, panic in :show modules after load failure
Simon Marlow <simonmar@microsoft.com>**20070926100732] 
[Remove current package from preloaded package set
Clemens Fruhwirth <clemens@endorphin.org>**20070926084802] 
[Fixing #1340, adding HPC Documentation
andy@galois.com**20070926055331] 
[TAG 2007-09-25
Ian Lynagh <igloo@earth.li>**20070925164536] 
Patch bundle hash:
2c0ec348acfa7704d20f3e556fdd5566df6e1c26
