1. 13 Jul, 2009 1 commit
  2. 03 Jun, 2009 1 commit
    • simonpj@microsoft.com's avatar
      Allow RULES for seq, and exploit them · 90ce88a0
      simonpj@microsoft.com authored
      Roman found situations where he had
            case (f n) of _ -> e
      where he knew that f (which was strict in n) would terminate if n did.
      Notice that the result of (f n) is discarded. So it makes sense to
      transform to
            case n of _ -> e
      
      Rather than attempt some general analysis to support this, I've added
      enough support that you can do this using a rewrite rule:
      
        RULE "f/seq" forall n.  seq (f n) e = seq n e
      
      You write that rule.  When GHC sees a case expression that discards
      its result, it mentally transforms it to a call to 'seq' and looks for
      a RULE.  (This is done in Simplify.rebuildCase.)  As usual, the
      correctness of the rule is up to you.
      
      This patch implements the extra stuff.  I have not documented it explicitly
      in the user manual yet... let's see how useful it is first.
      
      The patch looks bigger than it is, because
        a) Comments; see esp MkId Note [seqId magic]
      
        b) Some refactoring.  Notably, I moved the special desugaring for
           seq from MkCore back into DsUtils where it properly belongs.
           (It's really a desugaring thing, not a CoreSyn invariant.)
      
        c) Annoyingly, in a RULE left-hand side we need to be careful that
           the magical desugaring done in MkId Note [seqId magic] item (c) 
           is *not* done on the LHS of a rule. Or rather, we arrange to 
           un-do it, in DsBinds.decomposeRuleLhs.
      
      90ce88a0
  3. 07 Mar, 2009 1 commit
  4. 06 Mar, 2009 1 commit
  5. 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
           IfaceSyn.ifaceDeclSubBndrs
           HscTypes.implicitTyThings
           TidyPgm.getImplicitBinds
        (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.
      
      9ffadf21
  6. 20 Sep, 2008 1 commit
    • simonpj@microsoft.com's avatar
      Tidy up the treatment of dead binders · 7e8cba32
      simonpj@microsoft.com authored
      This patch does a lot of tidying up of the way that dead variables are
      handled in Core.  Just the sort of thing to do on an aeroplane.
      
      * The tricky "binder-swap" optimisation is moved from the Simplifier
        to the Occurrence Analyser.  See Note [Binder swap] in OccurAnal.
        This is really a nice change.  It should reduce the number of
        simplifier iteratoins (slightly perhaps).  And it means that
        we can be much less pessimistic about zapping occurrence info
        on binders in a case expression.  
      
      * For example:
      	case x of y { (a,b) -> e }
        Previously, each time around, even if y,a,b were all dead, the
        Simplifier would pessimistically zap their OccInfo, so that we
        can't see they are dead any more.  As a result virtually no 
        case expression ended up with dead binders.  This wasn't Bad
        in itself, but it always felt wrong.
      
      * I added a check to CoreLint to check that a dead binder really
        isn't used.  That showed up a couple of bugs in CSE. (Only in
        this sense -- they didn't really matter.)
        
      * I've changed the PprCore printer to print "_" for a dead variable.
        (Use -dppr-debug to see it again.)  This reduces clutter quite a
        bit, and of course it's much more useful with the above change.
      
      * Another benefit of the binder-swap change is that I could get rid of
        the Simplifier hack (working, but hacky) in which the InScopeSet was
        used to map a variable to a *different* variable. That allowed me
        to remove VarEnv.modifyInScopeSet, and to simplify lookupInScopeSet
        so that it doesn't look for a fixpoint.  This fixes no bugs, but 
        is a useful cleanup.
      
      * Roman pointed out that Id.mkWildId is jolly dangerous, because
        of its fixed unique.  So I've 
      
           - localied it to MkCore, where it is private (not exported)
      
           - renamed it to 'mkWildBinder' to stress that you should only
             use it at binding sites, unless you really know what you are
             doing
      
           - provided a function MkCore.mkWildCase that emodies the most
             common use of mkWildId, and use that elsewhere
      
         So things are much better
      
      * A knock-on change is that I found a common pattern of localising
        a potentially global Id, and made a function for it: Id.localiseId
      7e8cba32
  7. 16 Sep, 2008 1 commit
  8. 07 Aug, 2008 1 commit
  9. 31 Jul, 2008 2 commits
  10. 12 Apr, 2008 1 commit
  11. 26 Jan, 2008 1 commit
  12. 06 Dec, 2007 1 commit
  13. 19 Nov, 2007 1 commit
  14. 18 Nov, 2007 1 commit
  15. 17 Nov, 2007 1 commit
  16. 16 Nov, 2007 3 commits
  17. 04 Sep, 2007 1 commit
  18. 03 Sep, 2007 1 commit
  19. 01 Sep, 2007 1 commit
  20. 31 Aug, 2007 3 commits
  21. 30 Aug, 2007 3 commits
  22. 24 Aug, 2007 11 commits
  23. 23 Aug, 2007 1 commit