1. 23 May, 2015 2 commits
  2. 22 May, 2015 4 commits
    • Simon Peyton Jones's avatar
      Fix a huge space leak in the mighty Simplifier · 45d9a15c
      Simon Peyton Jones authored
      This long-standing, terrible, adn somewhat subtle bug was exposed
      by Trac #10370, thanks to Reid Barton's brilliant test case (comment:3).
      
      The effect is large on the Trac #10370 test.
      Here is what the profile report says:
      
      Before:
       total time  =       24.35 secs   (24353 ticks @ 1000 us, 1 processor)
       total alloc = 11,864,360,816 bytes  (excludes profiling overheads)
      
      After:
       total time  =       21.16 secs   (21160 ticks @ 1000 us, 1 processor)
       total alloc = 7,947,141,136 bytes  (excludes profiling overheads)
      
      The /combined/ effect of the tidyOccName fix, plus this one, is dramtic
      for Trac #10370.  Here is what +RTS -s says:
      
      Before:
        15,490,210,952 bytes allocated in the heap
         1,783,919,456 bytes maximum residency (20 sample(s))
      
        MUT     time   30.117s  ( 31.383s elapsed)
        GC      time   90.103s  ( 90.107s elapsed)
        Total   time  120.843s  (122.065s elapsed)
      
      After:
         7,928,671,936 bytes allocated in the heap
            52,914,832 bytes maximum residency (25 sample(s))
      
        MUT     time   13.912s  ( 15.110s elapsed)
        GC      time    6.809s  (  6.808s elapsed)
        Total   time   20.789s  ( 21.954s elapsed)
      
      - Heap allocation halved
      - Residency cut by a factor of more than 30.
      - ELapsed time cut by a factor of 6
      
      Not bad!
      
      The details
      ~~~~~~~~~~~
      The culprit was SimplEnv.mkCoreSubst, which used mapVarEnv to do some
      impedence-matching from the substitituion used by the simplifier to
      the one used by CoreSubst.  But the impedence-mactching was recursive!
      
        mk_subst tv_env cv_env id_env
          = CoreSubst.mkSubst in_scope tv_env cv_env (mapVarEnv fiddle id_env)
      
        fiddle (DoneEx e)          = e
        fiddle (DoneId v)          = Var v
        fiddle (ContEx tv cv id e) = CoreSubst.substExpr (mk_subst tv cv id) e
      
      Inside fiddle, in the ContEx case, we may do another whole level of
      fiddle.  And so on.  Moreover, UniqFM (which is built on Data.IntMap) is
      strict, so the fiddling is done eagerly.  I didn't wok through all the
      details but the result is a gargatuan blow-up of entirely unnecessary work.
      
      Laziness would make this go away, I think, but I don't want to mess
      with IntMap.  And in any case, the impedence matching is a royal pain.
      
      In the end I simply ceased trying to use CoreSubst.substExpr in the
      simplifier, and instead just use simplExpr.  That does mean bit of
      duplication; e.g.  new code for simplRules.  But it's not a big deal
      and it's far more direct and easy to reason about.
      
      A bit of knock-on refactoring:
      
       * Data type ArgSummary moves to CoreUnfold.
      
       * interestingArg moves from CoreUnfold to SimplUtils, and gets a
         SimplEnv argument which can be used when we encounter a variable.
      
       * simplLamBndrs, addBndrRules move from SimplEnv to Simplify
         (because they now calls simplUnfolding, simplRules resp)
      
       * SimplUtils.substExpr, substUnfolding, mkCoreSubst die completely
      
       * In Simplify some several functions that were previously pure
         substitution-based functions are now monadic:
           - addBndrRules, simplRule
           - addCoerce, add_coerce in simplCast
      
       * In case 2c of Simplify.rebuildCase, there was a pretty disgusting
         expression-substitution taking place for 'rhs'; and we really don't
         want to make that monadic becuase 'rhs' can be big.
         Solution: reduce the arity of the rules for seq.
         See Note [User-defined RULES for seq] in MkId.
      45d9a15c
    • Simon Peyton Jones's avatar
      Fix quadratic behaviour in tidyOccName · c89bd681
      Simon Peyton Jones authored
      In the test program from comment:3 of Trac #10370, it turned out
      that 25% of all compile time was going in OccName.tidyOccName!
      
      It was all becuase the algorithm for finding an unused OccName
      had a quadratic case.
      
      This patch fixes it.  THe effect is pretty big:
      
      Before:
      	total time  =       34.30 secs   (34295 ticks @ 1000 us, 1 processor)
      	total alloc = 15,496,011,168 bytes  (excludes profiling overheads)
      
      After
      	total time  =       25.41 secs   (25415 ticks @ 1000 us, 1 processor)
      	total alloc = 11,812,744,816 bytes  (excludes profiling overheads)
      c89bd681
    • Simon Peyton Jones's avatar
      Reduce magic for seqId · eae703aa
      Simon Peyton Jones authored
      An upcoming commit means that the RULES for 'seq' get only
      one value arg, not two.  This patch prepares for that by
      
      - reducing the arity of seq's built-in rule, to take one value arg
      - making 'seq' not inline on the LHS of RULES
      - and removing the horrid un-inlining in DsBinds.decomposeRuleLhs
      eae703aa
    • Simon Peyton Jones's avatar
      White space layout only · 369dd0c6
      Simon Peyton Jones authored
      369dd0c6
  3. 21 May, 2015 3 commits
    • Alan Zimmerman's avatar
      ApiAnnotatons : AnnDcolon in wrong place for PatBind · c488da85
      Alan Zimmerman authored
      Summary:
      In the following code fragment
      
          let ls :: Int = undefined
      
      the `::` is attached to the ls function as a whole, rather than to the
      pattern on the LHS.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D883
      
      GHC Trac Issues: #10396
      c488da85
    • Alan Zimmerman's avatar
      ApiAnnotations : parens around a context with wildcard loses annotations · 0df14b5d
      Alan Zimmerman authored
      Summary:
      In the following code, the extra set of parens around the context end up
      with detached annotations.
      
          {-# LANGUAGE PartialTypeSignatures #-}
          module ParensAroundContext where
      
          f :: ((Eq a, _)) => a -> a -> Bool
          f x y = x == y
      
      Trac ticket #10354
      
      It turns out it was the TupleTy that was the culprit.
      
      This may also solve #10315
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin, goldfire
      
      Reviewed By: austin
      
      Subscribers: goldfire, bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D868
      
      GHC Trac Issues: #10354, #10315
      0df14b5d
    • Alan Zimmerman's avatar
      ApiAnnotations : AST version of nested forall loses forall annotation · c553e980
      Alan Zimmerman authored
      Summary:
      When parsing
      
          {-# LANGUAGE ScopedTypeVariables #-}
      
          extremumNewton :: forall tag. forall tag1.
                             tag -> tag1 -> Int
          extremumNewton = undefined
      
      the parser creates nested HsForAllTy's for the two forall statements.
      
      These get flattened into a single one in `HsTypes.mk_forall_ty`
      
      This patch removes the flattening, so that API Annotations are not lost in the
      process.
      
      Test Plan: ./validate
      
      Reviewers: goldfire, austin, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: bgamari, mpickering, thomie, goldfire
      
      Differential Revision: https://phabricator.haskell.org/D836
      
      GHC Trac Issues: #10278, #10315, #10354, #10363
      c553e980
  4. 20 May, 2015 1 commit
  5. 19 May, 2015 12 commits
  6. 18 May, 2015 8 commits
    • Sergei Trofimovich's avatar
      includes/stg/SMP.h: implement simple load_/store_load_barrier on armv6 and older · eaaa38ba
      Sergei Trofimovich authored
      Assuming there is no real SMP systems on these CPUs
      I've added only compiler barrier (otherwise write_barrier
      and friends need to be fixed as well).
      
      Patch also fixes build breakage reported in #10244.
      Signed-off-by: default avatarSergei Trofimovich <siarheit@google.com>
      
      Reviewers: rwbarton, nomeata, austin
      
      Reviewed By: nomeata, austin
      
      Subscribers: bgamari, thomie
      
      Differential Revision: https://phabricator.haskell.org/D894
      
      GHC Trac Issues: #10244
      eaaa38ba
    • Simon Peyton Jones's avatar
      Make the "matchable-given" check happen first · 228ddb95
      Simon Peyton Jones authored
      This change makes the matchable-given check apply uniformly to
           - constraint tuples
           - natural numbers
           - Typeable
      as well as to vanilla class constraints.
      
      See Note [Instance and Given overlap] in TcInteract
      228ddb95
    • Simon Peyton Jones's avatar
      Refactor tuple constraints · ffc21506
      Simon Peyton Jones authored
      Make tuple constraints be handled by a perfectly ordinary
      type class, with the component constraints being the
      superclasses:
          class (c1, c2) => (c2, c2)
      
      This change was provoked by
      
        #10359  inability to re-use a given tuple
                constraint as a whole
      
        #9858   confusion between term tuples
                and constraint tuples
      
      but it's generally a very nice simplification. We get rid of
       -  In Type, the TuplePred constructor of PredTree,
          and all the code that dealt with TuplePreds
       -  In TcEvidence, the constructors EvTupleMk, EvTupleSel
      
      See Note [How tuples work] in TysWiredIn.
      
      Of course, nothing is ever entirely simple. This one
      proved quite fiddly.
      
      - I did quite a bit of renaming, which makes this patch
        touch a lot of modules. In partiuclar tupleCon -> tupleDataCon.
      
      - I made constraint tuples known-key rather than wired-in.
        This is different to boxed/unboxed tuples, but it proved
        awkward to have all the superclass selectors wired-in.
        Easier just to use the standard mechanims.
      
      - While I was fiddling with known-key names, I split the TH Name
        definitions out of DsMeta into a new module THNames.  That meant
        that the known-key names can all be gathered in PrelInfo, without
        causing module loops.
      
      - I found that the parser was parsing an import item like
            T( .. )
        as a *data constructor* T, and then using setRdrNameSpace to
        fix it.  Stupid!  So I changed the parser to parse a *type
        constructor* T, which means less use of setRdrNameSpace.
      
        I also improved setRdrNameSpace to behave better on Exact Names.
        Largely on priciple; I don't think it matters a lot.
      
      - When compiling a data type declaration for a wired-in thing like
        tuples (,), or lists, we don't really need to look at the
        declaration.  We have the wired-in thing!  And not doing so avoids
        having to line up the uniques for data constructor workers etc.
        See Note [Declarations for wired-in things]
      
      - I found that FunDeps.oclose wasn't taking superclasses into
        account; easily fixed.
      
      - Some error message refactoring for invalid constraints in TcValidity
      
      - Haddock needs to absorb the change too; so there is a submodule update
      ffc21506
    • Simon Peyton Jones's avatar
      Delete commented-out line · 76024fdb
      Simon Peyton Jones authored
      76024fdb
    • Simon Peyton Jones's avatar
      Test Trac #10248 · fa0bdd3d
      Simon Peyton Jones authored
      fa0bdd3d
    • Simon Peyton Jones's avatar
      Test Trac #10403 · f1f265df
      Simon Peyton Jones authored
      f1f265df
    • Simon Peyton Jones's avatar
      Test Trac #10359 · 3f42de51
      Simon Peyton Jones authored
      3f42de51
    • Joachim Breitner's avatar
      CmmCommonBlockElim: Improve hash function · 73f836f5
      Joachim Breitner authored
      Previously, the hash function used to cut down the number of block
      comparisons did not take local registers into account, causing far too
      many similar, but different bocks to be considered candidates for the
      (expensive!) comparision.
      
      Adding register to the hash takes CmmCommonBlockElim's share of the
      runtime of the example in #10397 from 17% to 2.5%, and eliminates all
      unwanted hash collisions.
      
      This patch also replaces the fancy trie by a plain Data.Map. It turned
      out to be not performance critical, so this simplifies the code.
      
      Differential Revision: https://phabricator.haskell.org/D896
      73f836f5
  7. 16 May, 2015 2 commits
  8. 15 May, 2015 1 commit
  9. 14 May, 2015 3 commits
  10. 13 May, 2015 4 commits