1. 22 Dec, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Make mkDFunUnfolding more robust · 3e0a7b9f
      simonpj@microsoft.com authored
      It now uses tcSplitDFunTy, which is designed for the purpose and
      allows arbitrary argument types to the dfun, rather than
      tcSplitSigmaTy.  This generality is used in DPH, which has
      internally-generated dfuns with impliciation-typed arguments.
      To do this I had to make tcSplitDFunTy return the number of
      arguments, so there are some minor knock-on effects in other
  2. 21 Dec, 2010 1 commit
  3. 01 Nov, 2010 1 commit
  4. 13 Dec, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Fix recursive superclasses (again). Fixes Trac #4809. · a3bab050
      simonpj@microsoft.com authored
      This patch finally deals with the super-delicate question of
      superclases in possibly-recursive dictionaries.  The key idea
      is the DFun Superclass Invariant (see TcInstDcls):
           In the body of a DFun, every superclass argument to the
           returned dictionary is
             either   * one of the arguments of the DFun,
             or       * constant, bound at top level
      To establish the invariant, we add new "silent" superclass
      argument(s) to each dfun, so that the dfun does not do superclass
      selection internally.  There's a bit of hoo-ha to make sure that
      we don't print those silent arguments in error messages; a knock
      on effect was a change in interface-file format.
      A second change is that instead of the complex and fragile
      "self dictionary binding" in TcInstDcls and TcClassDcl,
      using the same mechanism for existential pattern bindings.
      See Note [Subtle interaction of recursion and overlap] in TcInstDcls
      and Note [Binding when looking up instances] in InstEnv.
      Main notes are here:
        * Note [Silent Superclass Arguments] in TcInstDcls,
          including the DFun Superclass Invariant
      Main code changes are:
        * The code for MkId.mkDictFunId and mkDictFunTy
        * DFunUnfoldings get a little more complicated;
          their arguments are a new type DFunArg (in CoreSyn)
        * No "self" argument in tcInstanceMethod
        * No special tcSimplifySuperClasss
        * No "dependents" argument to EvDFunApp
         It turns out that it's quite tricky to generate the right
         DFunUnfolding for a specialised dfun, when you use SPECIALISE
         INSTANCE.  For now I've just commented it out (in DsBinds) but
         that'll lose some optimisation, and I need to get back to
  5. 03 Dec, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Fix up TcInstDcls · 081632b8
      simonpj@microsoft.com authored
      I really don't know how this module got left out of my last
      patch, namely
        Thu Dec  2 12:35:47 GMT 2010  simonpj@microsoft.com
        * Re-jig simplifySuperClass (again)
      I suggest you don't pull either the patch above, or this
      one, unless you really have to.  I'm not fully confident
      that it works properly yet.  Ran out of time. Sigh.
  6. 02 Dec, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Re-jig simplifySuperClass (again) · 5723262f
      simonpj@microsoft.com authored
      This fixes the current loop in T3731, and will fix other
      reported loops.  The loops show up when we are generating
      evidence for superclasses in an instance declaration.
      The trick is to make the "self" dictionary simplifySuperClass
      depend *explicitly* on the superclass we are currently trying
      to build.  See Note [Dependencies in self dictionaries] in TcSimplify.
      That in turn means that EvDFunApp needs a dependency-list, used
      when chasing dependencies in isGoodRecEv.
  7. 21 Oct, 2010 1 commit
  8. 07 Oct, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Implement auto-specialisation of imported Ids · 92267aa2
      simonpj@microsoft.com authored
      This big-ish patch arranges that if an Id 'f' is 
        * Type-class overloaded 
             f :: Ord a => [a] -> [a]
        * Defined with an INLINABLE pragma
             {-# INLINABLE f #-}
        * Exported from its defining module 'D'
      then in any module 'U' that imports D
      1. Any call of 'f' at a fixed type will generate 
         (a) a specialised version of f in U
         (b) a RULE that rewrites unspecialised calls to the
             specialised on
        e.g. if the call is (f Int dOrdInt xs) then the 
        specialiser will generate
           $sfInt :: [Int] -> [Int]
           $sfInt = <code for f, imported from D, specialised>
           {-# RULE forall d.  f Int d = $sfInt #-}
      2. In addition, you can give an explicit {-# SPECIALISE -#}
         pragma for the imported Id
           {-# SPECIALISE f :: [Bool] -> [Bool] #-}
         This too generates a local specialised definition, 
         and the corresponding RULE 
      The new RULES are exported from module 'U', so that any module
      importing U will see the specialised versions of 'f', and will
      not re-specialise them.
      There's a flag -fwarn-auto-orphan that warns you if the auto-generated
      RULES are orphan rules. It's not in -Wall, mainly to avoid lots of
      error messages with existing packages.
      Main implementation changes
       - A new flag on a CoreRule to say if it was auto-generated.
         This is persisted across interface files, so there's a small
         change in interface file format.
       - Quite a bit of fiddling with plumbing, to get the 
         {-# SPECIALISE #-} pragmas for imported Ids.  In particular, a
         new field tgc_imp_specs in TcGblEnv, to keep the specialise
         pragmas for imported Ids between the typechecker and the desugarer.
       - Some new code (although surprisingly little) in Specialise,
         to deal with calls of imported Ids
  9. 24 Sep, 2010 1 commit
  10. 15 Sep, 2010 2 commits
  11. 14 Sep, 2010 1 commit
  12. 13 Sep, 2010 1 commit
  13. 13 Aug, 2010 1 commit
  14. 21 Jul, 2010 1 commit
  15. 13 Jul, 2010 1 commit
  16. 07 Jul, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #4127 (and hence #4173) · f87cc9cf
      simonpj@microsoft.com authored
      The change involves a little refactoring, so that the default
      method Ids are brought into scope earlier, before the value
      declarations are compiled.  (Since a value decl may contain
      an instance decl in a quote.)
      See Note [Default method Ids and Template Haskell] in
  17. 31 May, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Robustify the treatement of DFunUnfolding · a90dc390
      simonpj@microsoft.com authored
      See Note [DFun unfoldings] in CoreSyn.  The issue here is that 
      you can't tell how many dictionary arguments a DFun needs just
      from looking at the Arity of the DFun Id: if the dictionary is
      represented by a newtype the arity might include the dictionary
      and value arguments of the (single) method.
      So we need to record the number of arguments need by the DFun
      in the DFunUnfolding itself.  Details in 
         Note [DFun unfoldings] in CoreSyn
  18. 25 May, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Refactor (again) the handling of default methods · 78693246
      simonpj@microsoft.com authored
      This patch fixes Trac #4056, by 
       a) tidying up the treatment of default method names
       b) removing the 'module' argument to newTopSrcBinder
      The details aren't that interesting, but the result
      is much tidier. The original bug was a 'nameModule' panic,
      caused by trying to find the module of a top-level name.
      But TH quotes generate Internal top-level names that don't
      have a module, and that is generally a good thing.  
      Fixing that in turn led to the default-method refactoring,
      which also makes the Name for a default method be handled
      in the same way as other derived names, generated in BuildTyCl
      via a call newImplicitBinder.  Hurrah.
  19. 09 Mar, 2010 1 commit
  20. 07 Jan, 2010 1 commit
  21. 06 Jan, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Improve the handling of default methods · 77166b17
      simonpj@microsoft.com authored
      See the long Note [INLINE and default methods].  
      This patch changes a couple of data types, with a knock-on effect on
      the format of interface files.  A lot of files get touched, but is a
      relatively minor change.  The main tiresome bit is the extra plumbing
      to communicate default methods between the type checker and the
  22. 05 Jan, 2010 1 commit
    • simonpj@microsoft.com's avatar
      Undo the fix for Trac #3772 and do it a new way · 9a4c93a5
      simonpj@microsoft.com authored
      The main idea is that I'm now treating a single-method dictionary very
      much like a multi-method dictionary.  In particular, it respond to
      exprIsConApp_maybe, even though newtypes aren't *really* proper
      See long comments with Note [Single-method classes] for why
      this slight hack is justified.
  23. 21 Dec, 2009 1 commit
  24. 18 Dec, 2009 2 commits
  25. 13 Nov, 2009 1 commit
  26. 12 Nov, 2009 1 commit
  27. 06 Nov, 2009 1 commit
  28. 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.
      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 
      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
          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%
  29. 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.
  30. 23 Jul, 2009 1 commit
    • 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.
  31. 06 Jul, 2009 1 commit
  32. 28 May, 2009 1 commit
  33. 27 May, 2009 1 commit
  34. 18 Mar, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Add the notion of "constructor-like" Ids for rule-matching · 4bc25e8c
      simonpj@microsoft.com authored
      This patch adds an optional CONLIKE modifier to INLINE/NOINLINE pragmas, 
         {-# NOINLINE CONLIKE [1] f #-}
      The effect is to allow applications of 'f' to be expanded in a potential
      rule match.  Example
        {-# RULE "r/f" forall v. r (f v) = f (v+1) #-}
      Consider the term
           let x = f v in ..x...x...(r x)...
      Normally the (r x) would not match the rule, because GHC would be scared
      about duplicating the redex (f v). However the CONLIKE modifier says to
      treat 'f' like a constructor in this situation, and "look through" the
      unfolding for x.  So (r x) fires, yielding (f (v+1)).
      The main changes are:
        - Syntax
        - The inlinePragInfo field of an IdInfo has a RuleMatchInfo
          component, which records whether or not the Id is CONLIKE.
          Of course, this needs to be serialised in interface files too.
        - The occurrence analyser (OccAnal) and simplifier (Simplify) treat
          CONLIKE thing like constructors, by ANF-ing them
        - New function coreUtils.exprIsExpandable is like exprIsCheap, but
          additionally spots applications of CONLIKE functions
        - A CoreUnfolding has a field that caches exprIsExpandable
        - The rule matcher consults this field.  See 
          Note [Expanding variables] in Rules.lhs.
      On the way I fixed a lurking variable bug in the way variables are
      expanded.  See Note [Do not expand locally-bound variables] in
      Rule.lhs.  I also did a bit of reformatting and refactoring in
      Rules.lhs, so the module has more lines changed than are really
  35. 30 Jan, 2009 1 commit
  36. 13 Jan, 2009 1 commit
  37. 02 Jan, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Make record selectors into ordinary functions · 9ffadf21
      simonpj@microsoft.com authored
      This biggish patch addresses Trac #2670.  The main effect is to make
      record selectors into ordinary functions, whose unfoldings appear in
      interface files, in contrast to their previous existence as magic
      "implicit Ids".  This means that the usual machinery of optimisation,
      analysis, and inlining applies to them, which was failing before when
      the selector was somewhat complicated.  (Which it can be when
      strictness annotations, unboxing annotations, and GADTs are involved.)
      The change involves the following points
      * Changes in Var.lhs to the representation of Var.  Now a LocalId can
        have an IdDetails as well as a GlobalId.  In particular, the
        information that an Id is a record selector is kept in the
        IdDetails.  While compiling the current module, the record selector
        *must* be a LocalId, so that it participates properly in compilation
        (free variables etc).
        This led me to change the (hidden) representation of Var, so that there
        is now only one constructor for Id, not two.
      * The IdDetails is persisted into interface files, so that an
        importing module can see which Ids are records selectors.
      * In TcTyClDecls, we generate the record-selector bindings in renamed,
        but not typechecked form.  In this way, we can get the typechecker
        to add all the types and so on, which is jolly helpful especially
        when GADTs or type families are involved.  Just like derived
        instance declarations.
        This is the big new chunk of 180 lines of code (much of which is
        commentary).  A call to the same function, mkAuxBinds, is needed in
        TcInstDcls for associated types.
      * The typechecker therefore has to pin the correct IdDetails on to 
        the record selector, when it typechecks it.  There was a neat way
        to do this, by adding a new sort of signature to HsBinds.Sig, namely
        IdSig.  This contains an Id (with the correct Name, Type, and IdDetails);
        the type checker uses it as the binder for the final binding.  This
        worked out rather easily.
      * Record selectors are no longer "implicit ids", which entails changes to
        (These three functions must agree.)
      * MkId.mkRecordSelectorId is deleted entirely, some 300+ lines (incl
        comments) of very error prone code.  Happy days.
      * A TyCon no longer contains the list of record selectors: 
        algTcSelIds is gone
      The renamer is unaffected, including the way that import and export of
      record selectors is handled.
      Other small things
      * IfaceSyn.ifaceDeclSubBndrs had a fragile test for whether a data
        constructor had a wrapper.  I've replaced that with an explicit flag
        in the interface file. More robust I hope.
      * I renamed isIdVar to isId, which touched a few otherwise-unrelated files.
  38. 31 Dec, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Fix Trac #2856: make deriving work for type families · 79a6f3fa
      simonpj@microsoft.com authored
      Darn, but TcDeriv is complicated, when type families get in on
      the act!  This patch makes GeneralisedNewtypeDeriving work 
      properly for type families.  I think.
      In order to do so, I found that GeneralisedNewtypeDeriving can
      work for recursive newtypes too -- and since families are conservatively
      marked recursive, that's a crucial part of the fix, and useful too.
      See Note [Recursive newtypes] in TcDeriv.