1. 15 Mar, 2019 1 commit
  2. 12 Dec, 2018 1 commit
    • Simon Peyton Jones's avatar
      Improvements to demand analysis · d77501cd
      Simon Peyton Jones authored
      This patch collects a few improvements triggered by Trac #15696,
      and fixing Trac #16029
      
      * Stop making toCleanDmd behave specially for unlifted types.
        This special case was the cause of stupid behaviour in Trac
        #16029.  And to my joy I discovered the let/app invariant
        rendered it unnecessary.  (Maybe the special case pre-dated
        the let/app invariant.)
      
        Result: less special-case handling in the compiler, and
        better perf for the compiled code.
      
      * In WwLib.mkWWstr_one, treat seqDmd like U(AAA).  It was not
        being so treated before, which again led to stupid code.
      
      * Update and improve Notes
      
      There are .stderr test wibbles because we get slightly different
      strictness signatures for an argumment of unlifted type:
          <L,U> rather than <S,U>        for Int#
          <S,U> rather than <S(S),U(U)>  for Int
      d77501cd
  3. 11 Dec, 2018 1 commit
    • Ben Gamari's avatar
      dmdAnal: Move handling of datacon strictness to mkWWstr_one · d549c081
      Ben Gamari authored
      Previously datacon strictness was accounted for when we demand analysed a case
      analysis. However, this results in pessimistic demands in some cases. For
      instance, consider the program (from T10482)
      
          data family Bar a
          data instance Bar (a, b) = BarPair !(Bar a) !(Bar b)
          newtype instance Bar Int = Bar Int
      
          foo :: Bar ((Int, Int), Int) -> Int -> Int
          foo f k =
            case f of
              BarPair x y -> case burble of
                                True -> case x of
                                          BarPair p q -> ...
                                False -> ...
      
      We really should be able to assume that `p` is already evaluated since it came
      from a strict field of BarPair.
      
      However, as written the demand analyser can not conclude this since we may end
      up in the False branch of the case on `burble` (which places no demand on `x`).
      By accounting for the data con strictness later, applied to the demand of the
      RHS, we get the strict demand signature we want.
      
      See Note [Add demands for strict constructors] for a more comprehensive
      discussion.
      
      Test Plan: Validate
      
      Reviewers: simonpj, osa1, goldfire
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15696
      
      Differential Revision: https://phabricator.haskell.org/D5226
      d549c081
  4. 15 Oct, 2018 1 commit
  5. 21 Aug, 2018 1 commit
    • Andreas Klebinger's avatar
      Replace most occurences of foldl with foldl'. · 09c1d5af
      Andreas Klebinger authored
      This patch adds foldl' to GhcPrelude and changes must occurences
      of foldl to foldl'. This leads to better performance especially
      for quick builds where GHC does not perform strictness analysis.
      
      It does change strictness behaviour when we use foldl' to turn
      a argument list into function applications. But this is only a
      drawback if code looks ONLY at the last argument but not at the first.
      And as the benchmarks show leads to fewer allocations in practice
      at O2.
      
      Compiler performance for Nofib:
      
      O2 Allocations:
              -1 s.d.                -----            -0.0%
              +1 s.d.                -----            -0.0%
              Average                -----            -0.0%
      
      O2 Compile Time:
              -1 s.d.                -----            -2.8%
              +1 s.d.                -----            +1.3%
              Average                -----            -0.8%
      
      O0 Allocations:
              -1 s.d.                -----            -0.2%
              +1 s.d.                -----            -0.1%
              Average                -----            -0.2%
      
      Test Plan: ci
      
      Reviewers: goldfire, bgamari, simonmar, tdammers, monoidal
      
      Reviewed By: bgamari, monoidal
      
      Subscribers: tdammers, rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4929
      09c1d5af
  6. 17 Oct, 2017 1 commit
  7. 19 Sep, 2017 1 commit
    • Herbert Valerio Riedel's avatar
      compiler: introduce custom "GhcPrelude" Prelude · f63bc730
      Herbert Valerio Riedel authored
      This switches the compiler/ component to get compiled with
      -XNoImplicitPrelude and a `import GhcPrelude` is inserted in all
      modules.
      
      This is motivated by the upcoming "Prelude" re-export of
      `Semigroup((<>))` which would cause lots of name clashes in every
      modulewhich imports also `Outputable`
      
      Reviewers: austin, goldfire, bgamari, alanz, simonmar
      
      Reviewed By: bgamari
      
      Subscribers: goldfire, rwbarton, thomie, mpickering, bgamari
      
      Differential Revision: https://phabricator.haskell.org/D3989
      f63bc730
  8. 05 May, 2017 1 commit
  9. 12 Apr, 2017 1 commit
  10. 06 Apr, 2017 1 commit
  11. 01 Apr, 2017 1 commit
    • rwbarton's avatar
      Stamp out space leaks from demand analysis · f2b10f35
      rwbarton authored
      This reduces peak memory usage by ~30% on my test case (DynFlags),
      and (probably as a result of reduced GC work) decreases compilation
      time by a few percent as well.
      
      Also fix a bug in seqStrDmd so that demeand info is fully evaluated.
      
      Reviewers: simonpj, austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: dfeuer, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3400
      f2b10f35
  12. 13 Mar, 2017 1 commit
  13. 01 Mar, 2017 1 commit
    • David Feuer's avatar
      Upgrade UniqSet to a newtype · cbe569a5
      David Feuer authored
      The fundamental problem with `type UniqSet = UniqFM` is that `UniqSet`
      has a key invariant `UniqFM` does not. For example, `fmap` over
      `UniqSet` will generally produce nonsense.
      
      * Upgrade `UniqSet` from a type synonym to a newtype.
      
      * Remove unused and shady `extendVarSet_C` and `addOneToUniqSet_C`.
      
      * Use cached unique in `tyConsOfType` by replacing
        `unitNameEnv (tyConName tc) tc` with `unitUniqSet tc`.
      
      Reviewers: austin, hvr, goldfire, simonmar, niteria, bgamari
      
      Reviewed By: niteria
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3146
      cbe569a5
  14. 28 Feb, 2017 1 commit
  15. 09 Feb, 2017 1 commit
  16. 01 Feb, 2017 1 commit
  17. 23 Jan, 2017 1 commit
  18. 18 Jan, 2017 1 commit
  19. 25 Aug, 2016 2 commits
    • Joachim Breitner's avatar
      DmdAnal: Add a final, safe iteration · 8d92b88d
      Joachim Breitner authored
      this fixes #12368.
      
      It also refactors dmdFix a bit, removes some redundancies (such as
      passing around an strictness signature right next to an id, when that id
      is guaranteed to have been annotated with that strictness signature).
      
      Note that when fixed-point iteration does not terminate, we
      conservatively delete their strictness signatures (set them to nopSig).
      But this loses the information on how its strict free variables are
      used!
      
      Lazily used variables already escape via lazy_fvs. We ensure that in the
      case of an aborted fixed-point iteration, also the strict variables are
      put there (with a conservative demand of topDmd).
      
      Differential Revision: https://phabricator.haskell.org/D2392
      8d92b88d
    • Joachim Breitner's avatar
      7a86f584
  20. 12 Jul, 2016 1 commit
    • Joachim Breitner's avatar
      Demand analyser: Implement LetUp rule (#12370) · 45d8f4eb
      Joachim Breitner authored
      This makes the implementation match the description in the paper more
      closely: There, a let binding that is not a function has first its body
      analised, and then the binding’s RHS. This way, the demand on the bound
      variable by the body can be fed into the RHS, yielding more precise
      results.
      
      Performance measurements do unfortunately not show significant
      improvements or regessions.
      
      Differential Revision: https://phabricator.haskell.org/D2395
      45d8f4eb
  21. 01 May, 2016 1 commit
  22. 15 Apr, 2016 1 commit
  23. 14 Apr, 2016 1 commit
    • Joachim Breitner's avatar
      Add a final demand analyzer run right before TidyCore · f4fd98c7
      Joachim Breitner authored
      in order to have precise used-once information in the exported
      strictness signatures, as well as precise used-once information on
      thunks. This avoids the bad effects of #11731.
      
      The subsequent worker-wrapper pass is responsible for removing the
      demand environment part of the strictness signature. It does not run
      after the final demand analyzer pass, so remove this also in CoreTidy.
      
      The subsequent worker-wrapper pass is also responsible for removing
      used-once-information from the demands and strictness signatures, as
      these might not be preserved by the simplifier. This is _not_ done by
      CoreTidy, because we _do_ want this information, as produced by the last
      round of the demand analyzer, to be available to the code generator.
      
      Differential Revision: https://phabricator.haskell.org/D2073
      f4fd98c7
  24. 06 Apr, 2016 1 commit
    • Joachim Breitner's avatar
      Demand Analyzer: Do not set OneShot information (second try) · 0f58d348
      Joachim Breitner authored
      as suggested in ticket:11770#comment:1. This code was buggy
      (#11770), and the occurrence analyzer does the same job anyways.
      
      This also elaborates the notes in the occurrence analyzer accordingly.
      
      Previously, the worker/wrapper code would go through lengths to transfer
      the oneShot annotations from the original function to both the worker
      and the wrapper. We now simply transfer the demand on the worker, and
      let the subsequent occurrence analyzer push this onto the lambda
      binders.
      
      This also requires the occurrence analyzer to do this more reliably.
      Previously, it would not hand out OneShot annotatoins to things that
      would not `certainly_inline` (and it might not have mattered, as the
      Demand Analysis might have handed out the annotations). Now we hand out
      one-shot annotations unconditionally.
      
      Differential Revision: https://phabricator.haskell.org/D2085
      0f58d348
  25. 31 Mar, 2016 2 commits
  26. 25 Feb, 2016 1 commit
    • manav's avatar
      Make warning names more consistent · 66584914
      manav authored
      - Replace "Sigs" with "Signatures" in WarningFlag data constructors.
      - Replace "PatSyn" with "PatternSynonym" in WarningFlag data
        constructors.
      - Deprecate "missing-local-sigs" in favor of "missing-local-signatures".
      - Deprecate "missing-exported-sigs" in favor of
        "missing-exported-signatures".
      - Deprecate "missing-pat-syn-signatures" in favor of
        "missing-pattern-synonym-signatures".
      - Replace "ddump-strsigs" with "ddump-str-signatures"
      
      These complete the tasks that were explicitly mentioned in #11583
      
      Test Plan:
      Executed `ghc --show-options` and verified that the flags were changed
      as expected.
      
      Reviewers: svenpanne, austin, bgamari
      
      Reviewed By: austin, bgamari
      
      Subscribers: mpickering, thomie
      
      Differential Revision: https://phabricator.haskell.org/D1939
      
      GHC Trac Issues: #11583
      66584914
  27. 11 Feb, 2016 1 commit
  28. 18 Jan, 2016 1 commit
    • Jan Stolarek's avatar
      Replace calls to `ptext . sLit` with `text` · b8abd852
      Jan Stolarek authored
      Summary:
      In the past the canonical way for constructing an SDoc string literal was the
      composition `ptext . sLit`.  But for some time now we have function `text` that
      does the same.  Plus it has some rules that optimize its runtime behaviour.
      This patch takes all uses of `ptext . sLit` in the compiler and replaces them
      with calls to `text`.  The main benefits of this patch are clener (shorter) code
      and less dependencies between module, because many modules now do not need to
      import `FastString`.  I don't expect any performance benefits - we mostly use
      SDocs to report errors and it seems there is little to be gained here.
      
      Test Plan: ./validate
      
      Reviewers: bgamari, austin, goldfire, hvr, alanz
      
      Subscribers: goldfire, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D1784
      b8abd852
  29. 07 Jan, 2016 1 commit
    • Simon Peyton Jones's avatar
      Make demand analysis understand catch · 9915b656
      Simon Peyton Jones authored
      As Trac #11222, and #10712 note, the strictness analyser
      needs to be rather careful about exceptions.  Previously
      it treated them as identical to divergence, but that
      won't quite do.
      
      See Note [Exceptions and strictness] in Demand, which
      explains the deal.
      
      Getting more strictness in 'catch' and friends is a
      very good thing.  Here is the nofib summary, keeping
      only the big ones.
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
      --------------------------------------------------------------------------------
                fasta          -0.1%     -6.9%     -3.0%     -3.0%     +0.0%
                  hpg          -0.1%     -2.0%     -6.2%     -6.2%     +0.0%
             maillist          -0.1%     -0.3%      0.08      0.09     +1.2%
      reverse-complem          -0.1%    -10.9%     -6.0%     -5.9%     +0.0%
               sphere          -0.1%     -4.3%      0.08      0.08     +0.0%
                 x2n1          -0.1%     -0.0%      0.00      0.00     +0.0%
      --------------------------------------------------------------------------------
                  Min          -0.2%    -10.9%    -17.4%    -17.3%     +0.0%
                  Max          -0.0%     +0.0%     +4.3%     +4.4%     +1.2%
       Geometric Mean          -0.1%     -0.3%     -2.9%     -3.0%     +0.0%
      
      On the way I did quite a bit of refactoring in Demand.hs
      9915b656
  30. 11 Dec, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Add kind equalities to GHC. · 67465497
      eir@cis.upenn.edu authored
      This implements the ideas originally put forward in
      "System FC with Explicit Kind Equality" (ICFP'13).
      
      There are several noteworthy changes with this patch:
       * We now have casts in types. These change the kind
         of a type. See new constructor `CastTy`.
      
       * All types and all constructors can be promoted.
         This includes GADT constructors. GADT pattern matches
         take place in type family equations. In Core,
         types can now be applied to coercions via the
         `CoercionTy` constructor.
      
       * Coercions can now be heterogeneous, relating types
         of different kinds. A coercion proving `t1 :: k1 ~ t2 :: k2`
         proves both that `t1` and `t2` are the same and also that
         `k1` and `k2` are the same.
      
       * The `Coercion` type has been significantly enhanced.
         The documentation in `docs/core-spec/core-spec.pdf` reflects
         the new reality.
      
       * The type of `*` is now `*`. No more `BOX`.
      
       * Users can write explicit kind variables in their code,
         anywhere they can write type variables. For backward compatibility,
         automatic inference of kind-variable binding is still permitted.
      
       * The new extension `TypeInType` turns on the new user-facing
         features.
      
       * Type families and synonyms are now promoted to kinds. This causes
         trouble with parsing `*`, leading to the somewhat awkward new
         `HsAppsTy` constructor for `HsType`. This is dispatched with in
         the renamer, where the kind `*` can be told apart from a
         type-level multiplication operator. Without `-XTypeInType` the
         old behavior persists. With `-XTypeInType`, you need to import
         `Data.Kind` to get `*`, also known as `Type`.
      
       * The kind-checking algorithms in TcHsType have been significantly
         rewritten to allow for enhanced kinds.
      
       * The new features are still quite experimental and may be in flux.
      
       * TODO: Several open tickets: #11195, #11196, #11197, #11198, #11203.
      
       * TODO: Update user manual.
      
      Tickets addressed: #9017, #9173, #7961, #10524, #8566, #11142.
      Updates Haddock submodule.
      67465497
  31. 03 Aug, 2015 1 commit
  32. 30 Jul, 2015 1 commit
    • Simon Peyton Jones's avatar
      Fix Trac #10694: CPR analysis · 499b926b
      Simon Peyton Jones authored
      In this commit
         commit 0696fc6d
         Author: Simon Peyton Jones <simonpj@microsoft.com>
         Date:   Fri Jun 26 11:40:01 2015 +0100
      
      I made an error in the is_var_scrut tests in extendEnvForProdAlt.
      
      This patch fixes it, thereby fixing Trac #10694.
      499b926b
  33. 21 Jul, 2015 1 commit
    • Simon Peyton Jones's avatar
      Improve strictness analysis for exceptions · 7c0fff41
      Simon Peyton Jones authored
      Two things here:
      
      * For exceptions-catching primops like catch#, we know
        that the main argument function will be called, so
        we can use strictApply1Dmd, rather than lazy
      
        Changes in primops.txt.pp
      
      * When a 'case' scrutinises a I/O-performing primop,
        the Note [IO hack in the demand analyser] was
        throwing away all strictness from the code that
        followed.
      
        I found that this was causing quite a bit of unnecessary
        reboxing in the (heavily used) function
        GHC.IO.Handle.Internals.wantReadableHandle
      
        So this patch prevents the hack applying when the
        case scrutinises a primop.  See the revised
        Note [IO hack in the demand analyser]
      
      Thse two things buy us quite a lot in programs that do a lot of IO.
      
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
      --------------------------------------------------------------------------------
                  hpg          -0.4%     -2.9%     -0.9%     -1.0%     +0.0%
      reverse-complem          -0.4%    -10.9%    +10.7%    +10.9%     +0.0%
               simple          -0.3%     -0.0%    +26.2%    +26.2%     +3.7%
               sphere          -0.3%     -6.3%      0.09      0.09     +0.0%
      --------------------------------------------------------------------------------
                  Min          -0.7%    -10.9%     -4.6%     -4.7%     -1.7%
                  Max          -0.2%     +0.0%    +26.2%    +26.2%     +6.5%
       Geometric Mean          -0.4%     -0.3%     +2.1%     +2.1%     +0.1%
      
      I think the increase in runtime for 'simple' is measurement error.
      7c0fff41
  34. 26 Jun, 2015 2 commits
    • Simon Peyton Jones's avatar
      Improve CPR behavior for strict constructors · 0696fc6d
      Simon Peyton Jones authored
      When working on Trac #10482 I noticed that we could give constructor
      arguments the CPR property if they are use strictly.
      
      This is documented carefully in
          Note [CPR in a product case alternative]
      and also
          Note [Initial CPR for strict binders]
      
      There are a bunch of intersting examples in
          Note [CPR examples]
      which I have added to the test suite as T10482a.
      
      I also added a test for #10482 itself.
      0696fc6d
    • Simon Peyton Jones's avatar
      Fix addDataConStrictness · 9014a7ee
      Simon Peyton Jones authored
      See Note [Add demands for strict constructors].
      
      The new bit is the test for isAbsDmd in addDataConStrictness.
      There was a cryptic note that said that this function
      should add a seqDmd even for Absent arguments, but that
      is definitely a bad thing (as the Note now says), causing
      unused arguments to be passed to the worker.
      
      Easy fix!
      9014a7ee
  35. 21 Apr, 2015 3 commits
    • Simon Peyton Jones's avatar
      Wibble to DmdAnal · 5c7e4db5
      Simon Peyton Jones authored
      This fixes a typo in d5773a49
          Teach DmdAnal that coercions are value arguments!
          (Trac #10288)
      
      Sorry about that; I'm not sure how it slipped through.
      5c7e4db5
    • Simon Peyton Jones's avatar
      Support unboxing for GADT product types · f2d1b7fc
      Simon Peyton Jones authored
      Beofre this commit we never unboxed GADT, even if they
      are perfectly civilised products.
      
      This patch liberalises unboxing slightly.
      See Note [Product types] in TyCon.
      
      Still to come
       - for strictness, we could maybe deal with existentials too
       - todo: unboxing constructor arguments
      f2d1b7fc
    • Simon Peyton Jones's avatar
      Teach DmdAnal about free coercion variables · 3bec1ac0
      Simon Peyton Jones authored
      Coercion variables are used in casts and coercions, so the demand
      analyser should jolly well not regard them as absent!
      
      In fact this bug never makes a difference because even absent
      unboxed-coercion arguments are passed anyway;
      see WwLib.mk_abesnt_let, which returns Nothing for coercion Ids.
      
      But it was simply wrong before and that is never cool.
      3bec1ac0