1. 01 Mar, 2010 1 commit
  2. 07 Jan, 2010 1 commit
  3. 07 Dec, 2009 1 commit
  4. 29 Oct, 2009 1 commit
    • simonpj@microsoft.com's avatar
      The Big INLINE Patch: totally reorganise way that INLINE pragmas work · 72462499
      simonpj@microsoft.com authored
      This patch has been a long time in gestation and has, as a
      result, accumulated some extra bits and bobs that are only
      loosely related.  I separated the bits that are easy to split
      off, but the rest comes as one big patch, I'm afraid.
      
      Note that:
       * It comes together with a patch to the 'base' library
       * Interface file formats change slightly, so you need to
         recompile all libraries
      
      The patch is mainly giant tidy-up, driven in part by the
      particular stresses of the Data Parallel Haskell project. I don't
      expect a big performance win for random programs.  Still, here are the
      nofib results, relative to the state of affairs without the patch
      
              Program           Size    Allocs   Runtime   Elapsed
      --------------------------------------------------------------------------------
                  Min         -12.7%    -14.5%    -17.5%    -17.8%
                  Max          +4.7%    +10.9%     +9.1%     +8.4%
       Geometric Mean          +0.9%     -0.1%     -5.6%     -7.3%
      
      The +10.9% allocation outlier is rewrite, which happens to have a
      very delicate optimisation opportunity involving an interaction
      of CSE and inlining (see nofib/Simon-nofib-notes). The fact that
      the 'before' case found the optimisation is somewhat accidental.
      Runtimes seem to go down, but I never kno wwhether to really trust
      this number.  Binary sizes wobble a bit, but nothing drastic.
      
      
      The Main Ideas are as follows.
      
      InlineRules
      ~~~~~~~~~~~
      When you say 
            {-# INLINE f #-}
            f x = <rhs>
      you intend that calls (f e) are replaced by <rhs>[e/x] So we
      should capture (\x.<rhs>) in the Unfolding of 'f', and never meddle
      with it.  Meanwhile, we can optimise <rhs> to our heart's content,
      leaving the original unfolding intact in Unfolding of 'f'.
      
      So the representation of an Unfolding has changed quite a bit
      (see CoreSyn).  An INLINE pragma gives rise to an InlineRule 
      unfolding.  
      
      Moreover, it's only used when 'f' is applied to the
      specified number of arguments; that is, the number of argument on 
      the LHS of the '=' sign in the original source definition. 
      For example, (.) is now defined in the libraries like this
         {-# INLINE (.) #-}
         (.) f g = \x -> f (g x)
      so that it'll inline when applied to two arguments. If 'x' appeared
      on the left, thus
         (.) f g x = f (g x)
      it'd only inline when applied to three arguments.  This slightly-experimental
      change was requested by Roman, but it seems to make sense.
      
      Other associated changes
      
      * Moving the deck chairs in DsBinds, which processes the INLINE pragmas
      
      * In the old system an INLINE pragma made the RHS look like
         (Note InlineMe <rhs>)
        The Note switched off optimisation in <rhs>.  But it was quite
        fragile in corner cases. The new system is more robust, I believe.
        In any case, the InlineMe note has disappeared 
      
      * The workerInfo of an Id has also been combined into its Unfolding,
        so it's no longer a separate field of the IdInfo.
      
      * Many changes in CoreUnfold, esp in callSiteInline, which is the critical
        function that decides which function to inline.  Lots of comments added!
      
      * exprIsConApp_maybe has moved to CoreUnfold, since it's so strongly
        associated with "does this expression unfold to a constructor application".
        It can now do some limited beta reduction too, which Roman found 
        was an important.
      
      Instance declarations
      ~~~~~~~~~~~~~~~~~~~~~
      It's always been tricky to get the dfuns generated from instance
      declarations to work out well.  This is particularly important in 
      the Data Parallel Haskell project, and I'm now on my fourth attempt,
      more or less.
      
      There is a detailed description in TcInstDcls, particularly in
      Note [How instance declarations are translated].   Roughly speaking
      we now generate a top-level helper function for every method definition
      in an instance declaration, so that the dfun takes a particularly
      stylised form:
        dfun a d1 d2 = MkD (op1 a d1 d2) (op2 a d1 d2) ...etc...
      
      In fact, it's *so* stylised that we never need to unfold a dfun.
      Instead ClassOps have a special rewrite rule that allows us to
      short-cut dictionary selection.  Suppose dfun :: Ord a -> Ord [a]
                                                  d :: Ord a
      Then   
          compare (dfun a d)  -->   compare_list a d 
      in one rewrite, without first inlining the 'compare' selector
      and the body of the dfun.
      
      To support this
      a) ClassOps have a BuiltInRule (see MkId.dictSelRule)
      b) DFuns have a special form of unfolding (CoreSyn.DFunUnfolding)
         which is exploited in CoreUnfold.exprIsConApp_maybe
      
      Implmenting all this required a root-and-branch rework of TcInstDcls
      and bits of TcClassDcl.
      
      
      Default methods
      ~~~~~~~~~~~~~~~
      If you give an INLINE pragma to a default method, it should be just
      as if you'd written out that code in each instance declaration, including
      the INLINE pragma.  I think that it now *is* so.  As a result, library
      code can be simpler; less duplication.
      
      
      The CONLIKE pragma
      ~~~~~~~~~~~~~~~~~~
      In the DPH project, Roman found cases where he had
      
         p n k = let x = replicate n k
                 in ...(f x)...(g x)....
      
         {-# RULE f (replicate x) = f_rep x #-}
      
      Normally the RULE would not fire, because doing so involves 
      (in effect) duplicating the redex (replicate n k).  A new
      experimental modifier to the INLINE pragma, {-# INLINE CONLIKE
      replicate #-}, allows you to tell GHC to be prepared to duplicate
      a call of this function if it allows a RULE to fire.
      
      See Note [CONLIKE pragma] in BasicTypes
      
      
      Join points
      ~~~~~~~~~~~
      See Note [Case binders and join points] in Simplify
      
      
      Other refactoring
      ~~~~~~~~~~~~~~~~~
      * I moved endPass from CoreLint to CoreMonad, with associated jigglings
      
      * Better pretty-printing of Core
      
      * The top-level RULES (ones that are not rules for locally-defined things)
        are now substituted on every simplifier iteration.  I'm not sure how
        we got away without doing this before.  This entails a bit more plumbing
        in SimplCore.
      
      * The necessary stuff to serialise and deserialise the new
        info across interface files.
      
      * Something about bottoming floats in SetLevels
            Note [Bottoming floats]
      
      * substUnfolding has moved from SimplEnv to CoreSubs, where it belongs
      
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs   Runtime   Elapsed
      --------------------------------------------------------------------------------
                 anna          +2.4%     -0.5%      0.16      0.17
                 ansi          +2.6%     -0.1%      0.00      0.00
                 atom          -3.8%     -0.0%     -1.0%     -2.5%
               awards          +3.0%     +0.7%      0.00      0.00
               banner          +3.3%     -0.0%      0.00      0.00
           bernouilli          +2.7%     +0.0%     -4.6%     -6.9%
                boyer          +2.6%     +0.0%      0.06      0.07
               boyer2          +4.4%     +0.2%      0.01      0.01
                 bspt          +3.2%     +9.6%      0.02      0.02
            cacheprof          +1.4%     -1.0%    -12.2%    -13.6%
             calendar          +2.7%     -1.7%      0.00      0.00
             cichelli          +3.7%     -0.0%      0.13      0.14
              circsim          +3.3%     +0.0%     -2.3%     -9.9%
             clausify          +2.7%     +0.0%      0.05      0.06
        comp_lab_zift          +2.6%     -0.3%     -7.2%     -7.9%
             compress          +3.3%     +0.0%     -8.5%     -9.6%
            compress2          +3.6%     +0.0%    -15.1%    -17.8%
          constraints          +2.7%     -0.6%    -10.0%    -10.7%
         cryptarithm1          +4.5%     +0.0%     -4.7%     -5.7%
         cryptarithm2          +4.3%    -14.5%      0.02      0.02
                  cse          +4.4%     -0.0%      0.00      0.00
                eliza          +2.8%     -0.1%      0.00      0.00
                event          +2.6%     -0.0%     -4.9%     -4.4%
               exp3_8          +2.8%     +0.0%     -4.5%     -9.5%
               expert          +2.7%     +0.3%      0.00      0.00
                  fem          -2.0%     +0.6%      0.04      0.04
                  fft          -6.0%     +1.8%      0.05      0.06
                 fft2          -4.8%     +2.7%      0.13      0.14
             fibheaps          +2.6%     -0.6%      0.05      0.05
                 fish          +4.1%     +0.0%      0.03      0.04
                fluid          -2.1%     -0.2%      0.01      0.01
               fulsom          -4.8%     +9.2%     +9.1%     +8.4%
               gamteb          -7.1%     -1.3%      0.10      0.11
                  gcd          +2.7%     +0.0%      0.05      0.05
          gen_regexps          +3.9%     -0.0%      0.00      0.00
               genfft          +2.7%     -0.1%      0.05      0.06
                   gg          -2.7%     -0.1%      0.02      0.02
                 grep          +3.2%     -0.0%      0.00      0.00
               hidden          -0.5%     +0.0%    -11.9%    -13.3%
                  hpg          -3.0%     -1.8%     +0.0%     -2.4%
                  ida          +2.6%     -1.2%      0.17     -9.0%
                infer          +1.7%     -0.8%      0.08      0.09
              integer          +2.5%     -0.0%     -2.6%     -2.2%
            integrate          -5.0%     +0.0%     -1.3%     -2.9%
              knights          +4.3%     -1.5%      0.01      0.01
                 lcss          +2.5%     -0.1%     -7.5%     -9.4%
                 life          +4.2%     +0.0%     -3.1%     -3.3%
                 lift          +2.4%     -3.2%      0.00      0.00
            listcompr          +4.0%     -1.6%      0.16      0.17
             listcopy          +4.0%     -1.4%      0.17      0.18
             maillist          +4.1%     +0.1%      0.09      0.14
               mandel          +2.9%     +0.0%      0.11      0.12
              mandel2          +4.7%     +0.0%      0.01      0.01
              minimax          +3.8%     -0.0%      0.00      0.00
              mkhprog          +3.2%     -4.2%      0.00      0.00
           multiplier          +2.5%     -0.4%     +0.7%     -1.3%
             nucleic2          -9.3%     +0.0%      0.10      0.10
                 para          +2.9%     +0.1%     -0.7%     -1.2%
            paraffins         -10.4%     +0.0%      0.20     -1.9%
               parser          +3.1%     -0.0%      0.05      0.05
              parstof          +1.9%     -0.0%      0.00      0.01
                  pic          -2.8%     -0.8%      0.01      0.02
                power          +2.1%     +0.1%     -8.5%     -9.0%
               pretty         -12.7%     +0.1%      0.00      0.00
               primes          +2.8%     +0.0%      0.11      0.11
            primetest          +2.5%     -0.0%     -2.1%     -3.1%
               prolog          +3.2%     -7.2%      0.00      0.00
               puzzle          +4.1%     +0.0%     -3.5%     -8.0%
               queens          +2.8%     +0.0%      0.03      0.03
              reptile          +2.2%     -2.2%      0.02      0.02
              rewrite          +3.1%    +10.9%      0.03      0.03
                 rfib          -5.2%     +0.2%      0.03      0.03
                  rsa          +2.6%     +0.0%      0.05      0.06
                  scc          +4.6%     +0.4%      0.00      0.00
                sched          +2.7%     +0.1%      0.03      0.03
                  scs          -2.6%     -0.9%     -9.6%    -11.6%
               simple          -4.0%     +0.4%    -14.6%    -14.9%
                solid          -5.6%     -0.6%     -9.3%    -14.3%
              sorting          +3.8%     +0.0%      0.00      0.00
               sphere          -3.6%     +8.5%      0.15      0.16
               symalg          -1.3%     +0.2%      0.03      0.03
                  tak          +2.7%     +0.0%      0.02      0.02
            transform          +2.0%     -2.9%     -8.0%     -8.8%
             treejoin          +3.1%     +0.0%    -17.5%    -17.8%
            typecheck          +2.9%     -0.3%     -4.6%     -6.6%
              veritas          +3.9%     -0.3%      0.00      0.00
                 wang          -6.2%     +0.0%      0.18     -9.8%
            wave4main         -10.3%     +2.6%     -2.1%     -2.3%
         wheel-sieve1          +2.7%     -0.0%     +0.3%     -0.6%
         wheel-sieve2          +2.7%     +0.0%     -3.7%     -7.5%
                 x2n1          -4.1%     +0.1%      0.03      0.04
      --------------------------------------------------------------------------------
                  Min         -12.7%    -14.5%    -17.5%    -17.8%
                  Max          +4.7%    +10.9%     +9.1%     +8.4%
       Geometric Mean          +0.9%     -0.1%     -5.6%     -7.3%
      72462499
  5. 21 Aug, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #3423: missed instantiation for newtype-derived instances · b70fc87d
      simonpj@microsoft.com authored
      Somehow I'd forgotten to instantiate the coercion that is stored in a
      'NewtypeDerived' constructor in an InstInfo.  The necessary code is
      in TcInstDcls.tc_inst_decl2.
      
      The result was ghc: panic! (the 'impossible' happened)
         (GHC version 6.10.3 for x86_64-unknown-linux):
         No match in record selector Var.tcTyVarDetails
      because we were looking at an (uninstantiated) TyVar instead of
      an (instantiated) TcTyVar.
      b70fc87d
  6. 23 Jul, 2009 2 commits
    • simonpj@microsoft.com's avatar
      Fix Trac #3391: make generic to/from bindings only for newly-declared types · 27bc2857
      simonpj@microsoft.com authored
      Before this patch we were bogusly making to/from bindings for all data types
      in the TcGblEnv.  But that is wrong when we have multiple "chunks" of 
      bindings in Template Haskell.  We should start from the declarations 
      themselves.  Easy.
      27bc2857
    • simonpj@microsoft.com's avatar
      Fix Trac #3012: allow more free-wheeling in standalone deriving · aa0c0de9
      simonpj@microsoft.com authored
      In standalone deriving, we now do *not* check side conditions.
      We simply generate the code and typecheck it.  If there's a type
      error, it's the programmer's problem. 
      
      This means that you can do 'deriving instance Show (T a)', where
      T is a GADT, for example, provided of course that the boilerplate
      code does in fact typecheck.
      
      I put some work into getting a decent error message.  In particular
      if there's a type error in a method, GHC will show the entire code
      for that method (since, after all, the user did not write it).
      Most of the changes are to achieve that goal.
      
      Still to come: changes in the documentation.
      aa0c0de9
  7. 28 May, 2009 1 commit
  8. 27 May, 2009 1 commit
  9. 16 Mar, 2009 1 commit
  10. 13 Mar, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #3087: derived Data now defines dataCast1/2 · 8fda9784
      simonpj@microsoft.com authored
      This patch generates code in deriving(Data) for dataCast1 or 2 as
      appropriate.
      
      While I was there I did some refactoring (of course), pulling out
      the TcDeriv.inferConstraints as a separate function.
      
      I don't think it's worth merging this to 6.10.2, even though it's a bugfix,
      because it modifies code that I added in the HEAD only (for deriving Functor)
      so the merge will be sligtly awkward.  And there's an easy workaround.
      8fda9784
  11. 03 Mar, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #3057 in deriving Functor · 22eefb51
      simonpj@microsoft.com authored
      The universal type variables of a data constructor are not necessarily
      identical to those of its parent type constructor, especially if the
      data type is imported.
      
      While I was at it, I did a significant refactoring to make all this
      traversal of types more comprehensible, by adding the data type
      FFoldType.
      22eefb51
  12. 04 Feb, 2009 1 commit
  13. 02 Feb, 2009 1 commit
  14. 31 Dec, 2008 3 commits
  15. 30 Dec, 2008 1 commit
  16. 29 Oct, 2008 1 commit
  17. 27 Oct, 2008 1 commit
  18. 25 Oct, 2008 1 commit
  19. 21 Oct, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #2668, and refactor TcDeriv · da1de991
      simonpj@microsoft.com authored
      TcDeriv deals with both standalone and ordinary 'deriving';
      and with both data types and 'newtype deriving'.  The result
      is really rather compilcated and ad hoc.  Ryan discovered
      #2668; this patch fixes that bug, and makes the internal interfces
      #more uniform.  Specifically, the business of knocking off 
      type arguments from the instance type until it matches the kind of the
      class, is now done by derivTyData, not mkNewTypeEqn, because the
      latter is shared with standalone derriving, whree the trimmed
      type application is what the user wrote.
      da1de991
  20. 15 Oct, 2008 1 commit
  21. 17 Sep, 2008 1 commit
  22. 26 Aug, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Fix flaggery for RULES (cf Trac #2497) · 24b1e136
      simonpj@microsoft.com authored
      This patch executes the plan described in the discussion in Trac #2497.
      Specficially:
      
          * Inside a RULE, switch on the forall-as-keyword in the lexer,
            unconditionally. (Actually this is done by an earlier patch.)
      
          * Merge the -XScopedTypeVariables and -XPatternSignatures flags,
            and deprecate the latter. Distinguishing them isn't senseless,
            but it's jolly confusing.
      
          * Inside a RULE, switch on -XScopedTypeVariables unconditionally. 
      
          * Change -frewrite-rules to -fenable-rewrite-rules; deprecate the former. 
            Internally the DynFlag is now Opt_EnableRewriteRules.
      
      There's a test in typecheck/should_compile/T2497.hs
      24b1e136
  23. 05 Aug, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #2449 · 8303bba8
      simonpj@microsoft.com authored
      Deriving isn't allowed in hs-boot files (says the user manual)
      This patch checks properly instead of crashing!
      8303bba8
  24. 04 Aug, 2008 2 commits
  25. 01 Jul, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Several fixes to 'deriving' including Trac #2378 · 9319fbaf
      simonpj@microsoft.com authored
      This patch collects several related things together.
      
      * Refactor TcDeriv so that the InstInfo and the method bindings are renamed
        together.  This was messy before, and is cleaner now.  Fixes a bug caused 
        by interaction between the "auxiliary bindings" (which were given 
        Original names before), and stand-alone deriving (which meant that those
        Original names came from a different module). Now the names are purely
        local an ordinary.
      
        To do this, InstInfo is parameterised like much else HsSyn stuff.
      
      * Improve the location info in a dfun, which in turn improves location 
        info for error messages, e.g. overlapping instances
      
      * Make sure that newtype-deriving isn't used for Typeable1 and friends.
        (Typeable was rightly taken care of, but not Typeable1,2, etc.)
      
      * Check for data types in deriving Data, so that you can't do, say,
       	deriving instance Data (IO a)
      
      * Decorate the derived binding with location info from the *instance* 
        rather than from the *tycon*.  Again, this really only matters with
        standalone deriving, but it makes a huge difference there.
      
      I think that's it.  Quite a few error messages change slightly.
      
      If we release 6.8.4, this should go in if possible.
      9319fbaf
  26. 25 Jun, 2008 1 commit
  27. 16 Jun, 2008 1 commit
    • Ian Lynagh's avatar
      More commandline flag improvements · 0f5e104c
      Ian Lynagh authored
      * Allow -ffoo flags to be deprecated
      * Mark some -ffoo flags as deprecated
      * Avoid using deprecated flags in error messages, in the build system, etc
      * Add a flag to en/disable the deprecated flag warning
      0f5e104c
  28. 06 Jun, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #2334: validity checking for type families · 1c05d4fb
      simonpj@microsoft.com authored
      When we deal with a family-instance declaration (TcTyClsDecls.tcFamInstDecl)
      we must check the TyCon for validity; for example, that a newtype has exactly
      one field.  That is done all-at-once for normal declarations, and had been
      forgotten altogether for families.
      
      I also refactored the interface to tcFamInstDecl1 slightly.
      
      
      A slightly separate matter: if there's an error in family instances
      (e.g. overlap) we get a confusing error message cascade if we attempt to
      deal with 'deriving' clauses too; this patch bales out earlier in that case.
      
      
      Another slightly separate matter: standalone deriving for family 
      instances can legitimately have more specific types, just like normal
      data decls. For example
         
         data instance F [a] = ...
         deriving instance (Eq a, Eq b) => Eq (F [(a,b)])
      
      So tcLookupFamInstExact can a bit more forgiving than it was.
       
      1c05d4fb
  29. 12 Apr, 2008 1 commit
  30. 29 Mar, 2008 1 commit
  31. 17 Jan, 2008 2 commits
  32. 21 Dec, 2007 1 commit
    • simonpj@microsoft.com's avatar
      Improve handling of newtypes (fixes Trac 1495) · 219f900f
      simonpj@microsoft.com authored
      In a few places we want to "look through" newtypes to get to the
      representation type.  But we need to be careful that  we don't fall 
      into an ininite loop with e.g.
      	newtype T = MkT T
      
      The old mechansim for doing this was to have a field nt_rep, inside 
      a newtype TyCon, that gave the "ultimate representation" of the type.
      But that failed for Trac 1495, which looked like this:
         newtype Fix a = Fix (a (Fix a))
         data I a = I a
      Then, expanding the type (Fix I) went on for ever.
      
      The right thing to do seems to be to check for loops when epxanding
      the *type*, rather than in the *tycon*.  This patch does that, 
      	- Removes nt_rep from TyCon
      	- Make Type.repType check for loops
      See Note [Expanding newtypes] in Type.lhs.
      
      At the same time I also fixed a bug for Roman, where newtypes were not
      being expanded properly in FamInstEnv.topNormaliseType.  This function
      and Type.repType share a common structure.
      
      
      	Ian, see if this merges easily to the branch
      	If not, I don't think it's essential to fix 6.8
      219f900f
  33. 28 Nov, 2007 1 commit
  34. 21 Nov, 2007 1 commit
  35. 20 Nov, 2007 1 commit
    • simonpj@microsoft.com's avatar
      FIX Trac #1825: standalone deriving Typeable · f22f248b
      simonpj@microsoft.com authored
      Standalone deriving of typeable now requires you to say
      	instance Typeable1 Maybe
      which is exactly the shape of instance decl that is generated
      by a 'deriving( Typeable )' clause on the data type decl.
      
      This is a bit horrid, but it's the only consistent way, at least
      for now.  If you say something else, the error messages are helpful.
      
      MERGE to 6.8 branch
      f22f248b