1. 23 Jan, 2017 1 commit
  2. 20 Jan, 2017 2 commits
    • takano-akio's avatar
      Allow top-level string literals in Core (#8472) · d49b2bb2
      takano-akio authored
      This commits relaxes the invariants of the Core syntax so that a
      top-level variable can be bound to a primitive string literal of type
      Addr#.
      
      This commit:
      
      * Relaxes the invatiants of the Core, and allows top-level bindings whose
        type is Addr# as long as their RHS is either a primitive string literal or
        another variable.
      
      * Allows the simplifier and the full-laziness transformer to float out
        primitive string literals to the top leve.
      
      * Introduces the new StgGenTopBinding type to accomodate top-level Addr#
        bindings.
      
      * Introduces a new type of labels in the object code, with the suffix "_bytes",
        for exported top-level Addr# bindings.
      
      * Makes some built-in rules more robust. This was necessary to keep them
        functional after the above changes.
      
      This is a continuation of D2554.
      
      Rebasing notes:
      This had two slightly suspicious performance regressions:
      
      * T12425: bytes allocated regressed by roughly 5%
      * T4029: bytes allocated regressed by a bit over 1%
      * T13035: bytes allocated regressed by a bit over 5%
      
      These deserve additional investigation.
      
      Rebased by: bgamari.
      
      Test Plan: ./validate --slow
      
      Reviewers: goldfire, trofi, simonmar, simonpj, austin, hvr, bgamari
      
      Reviewed By: trofi, simonpj, bgamari
      
      Subscribers: trofi, simonpj, gridaphobe, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2605
      
      GHC Trac Issues: #8472
      d49b2bb2
    • Simon Peyton Jones's avatar
      Simplify and improve CSE · b78fa759
      Simon Peyton Jones authored
      Trac #13156 showed a lost opportunity for CSE. I found that it was
      easy to fix, and it had the nice side effect of rendering a previous
      nasty case, described in Note [Corner case for case expressions],
      unnecessary.
      
      Simpler code, does more.  Great.
      b78fa759
  3. 19 Jan, 2017 1 commit
    • Richard Eisenberg's avatar
      Update levity polymorphism · e7985ed2
      Richard Eisenberg authored
      This commit implements the proposal in
      https://github.com/ghc-proposals/ghc-proposals/pull/29 and
      https://github.com/ghc-proposals/ghc-proposals/pull/35.
      
      Here are some of the pieces of that proposal:
      
      * Some of RuntimeRep's constructors have been shortened.
      
      * TupleRep and SumRep are now parameterized over a list of RuntimeReps.
      * This
      means that two types with the same kind surely have the same
      representation.
      Previously, all unboxed tuples had the same kind, and thus the fact
      above was
      false.
      
      * RepType.typePrimRep and friends now return a *list* of PrimReps. These
      functions can now work successfully on unboxed tuples. This change is
      necessary because we allow abstraction over unboxed tuple types and so
      cannot
      always handle unboxed tuples specially as we did before.
      
      * We sometimes have to create an Id from a PrimRep. I thus split PtrRep
      * into
      LiftedRep and UnliftedRep, so that the created Ids have the right
      strictness.
      
      * The RepType.RepType type was removed, as it didn't seem to help with
      * much.
      
      * The RepType.repType function is also removed, in favor of typePrimRep.
      
      * I have waffled a good deal on whether or not to keep VoidRep in
      TyCon.PrimRep. In the end, I decided to keep it there. PrimRep is *not*
      represented in RuntimeRep, and typePrimRep will never return a list
      including
      VoidRep. But it's handy to have in, e.g., ByteCodeGen and friends. I can
      imagine another design choice where we have a PrimRepV type that is
      PrimRep
      with an extra constructor. That seemed to be a heavier design, though,
      and I'm
      not sure what the benefit would be.
      
      * The last, unused vestiges of # (unliftedTypeKind) have been removed.
      
      * There were several pretty-printing bugs that this change exposed;
      * these are fixed.
      
      * We previously checked for levity polymorphism in the types of binders.
      * But we
      also must exclude levity polymorphism in function arguments. This is
      hard to check
      for, requiring a good deal of care in the desugarer. See Note [Levity
      polymorphism
      checking] in DsMonad.
      
      * In order to efficiently check for levity polymorphism in functions, it
      * was necessary
      to add a new bit of IdInfo. See Note [Levity info] in IdInfo.
      
      * It is now safe for unlifted types to be unsaturated in Core. Core Lint
      * is updated
      accordingly.
      
      * We can only know strictness after zonking, so several checks around
      * strictness
      in the type-checker (checkStrictBinds, the check for unlifted variables
      under a ~
      pattern) have been moved to the desugarer.
      
      * Along the way, I improved the treatment of unlifted vs. banged
      * bindings. See
      Note [Strict binds checks] in DsBinds and #13075.
      
      * Now that we print type-checked source, we must be careful to print
      * ConLikes correctly.
      This is facilitated by a new HsConLikeOut constructor to HsExpr.
      Particularly troublesome
      are unlifted pattern synonyms that get an extra void# argument.
      
      * Includes a submodule update for haddock, getting rid of #.
      
      * New testcases:
        typecheck/should_fail/StrictBinds
        typecheck/should_fail/T12973
        typecheck/should_run/StrictPats
        typecheck/should_run/T12809
        typecheck/should_fail/T13105
        patsyn/should_fail/UnliftedPSBind
        typecheck/should_fail/LevPolyBounded
        typecheck/should_compile/T12987
        typecheck/should_compile/T11736
      
      * Fixed tickets:
        #12809
        #12973
        #11736
        #13075
        #12987
      
      * This also adds a test case for #13105. This test case is
      * "compile_fail" and
      succeeds, because I want the testsuite to monitor the error message.
      When #13105 is fixed, the test case will compile cleanly.
      e7985ed2
  4. 18 Jan, 2017 2 commits
  5. 17 Jan, 2017 2 commits
  6. 15 Jan, 2017 1 commit
  7. 13 Jan, 2017 2 commits
    • Facundo Domínguez's avatar
      Desugar static forms to makeStatic calls. · 13a85211
      Facundo Domínguez authored
      Summary:
      Using makeStatic instead of applications of the StaticPtr data
      constructor makes possible linting core when unboxing strict
      fields.
      
      Test Plan: ./validate
      
      Reviewers: simonpj, goldfire, austin, bgamari, hvr
      
      Reviewed By: simonpj
      
      Subscribers: RyanGlScott, mboes, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2930
      
      GHC Trac Issues: #12622
      13a85211
    • Simon Peyton Jones's avatar
      Record evaluated-ness on workers and wrappers · 6b976eb8
      Simon Peyton Jones authored
      In Trac #13027, comment:20, I noticed that wrappers created after
      demand analysis weren't recording the evaluated-ness of strict
      constructor arguments.  In the ticket that led to a (debatable)
      Lint error but in general the more we know about evaluated-ness
      the better we can optimise.
      
      This commit adds that info both in the worker (on args) and in
      the wrapper (on CPR result patterns).
      
      See Note [Record evaluated-ness in worker/wrapper] in WwLib
      
      On the way I defined Id.setCaseBndrEvald, and used it to shorten
      the code in a few other places
      6b976eb8
  8. 12 Jan, 2017 1 commit
  9. 09 Jan, 2017 1 commit
  10. 06 Jan, 2017 3 commits
    • Facundo Domínguez's avatar
      c5452cc1
    • Facundo Domínguez's avatar
      Have addModFinalizer expose the local type environment. · e5d1ed9c
      Facundo Domínguez authored
      Summary:
      Kind inference in ghci was interfered when renaming of type splices
      introduced the HsSpliced data constructor. This patch has kind
      inference skip over it.
      
      Test Plan: ./validate
      
      Reviewers: simonpj, rrnewton, austin, goldfire, bgamari
      
      Reviewed By: goldfire, bgamari
      
      Subscribers: thomie, mboes
      
      Differential Revision: https://phabricator.haskell.org/D2886
      
      GHC Trac Issues: #12985
      e5d1ed9c
    • Simon Peyton Jones's avatar
      Fix the implementation of the "push rules" · b4f2afe7
      Simon Peyton Jones authored
      Richard pointed out (comment:12 of Trac #13025) that my
      implementation of the coercion "push rules", newly added
      in exprIsConAppMaybe by commit b4c3a668, wasn't quite right.
      
      But in fact that means that the implementation of those same
      rules in Simplify.simplCast was wrong too.
      
      Hence this commit:
      
      * Refactor the push rules so they are implemented in just
        one place (CoreSubst.pushCoArgs, pushCoTyArg, pushCoValArg)
        The code in Simplify gets simpler, which is nice.
      
      * Fix the bug that Richard pointed out (to do with hetero-kinded
        coercions)
      
      Then compiler performance worsened, which led mt do discover
      two performance bugs:
      
      * The smart constructor Coercion.mkNthCo didn't have a case
        for ForAllCos, which meant we stupidly build a complicated
        coercion where a simple one would do
      
      * In OptCoercion there was one place where we used CoherenceCo
        (the data constructor) rather than mkCoherenceCo (the smart
        constructor), which meant that the the stupid complicated
        coercion wasn't optimised away
      
      For reasons I don't fully understand, T5321Fun did 2% less compiler
      allocation after all this, which is good.
      b4f2afe7
  11. 05 Jan, 2017 2 commits
    • Simon Peyton Jones's avatar
      Minor refactoring in CSE · c909e6ec
      Simon Peyton Jones authored
      I noticed that CSE.addBinding was always returning one of its own
      inputs, so I refactored to avoid doing so.
      
      No change in behaviour.
      c909e6ec
    • Simon Peyton Jones's avatar
      Remove a redundant test · 26646418
      Simon Peyton Jones authored
      postInlineUnconditionally was testing for isExportedId, but it was
      /also/ testing for top-level-ness, which is redundant.  This patch
      just removes the redundant test, and documents it.
      26646418
  12. 04 Jan, 2017 1 commit
  13. 26 Dec, 2016 1 commit
    • Joachim Breitner's avatar
      CallArity: Use exprIsCheap to detect thunks · 815099cc
      Joachim Breitner authored
      Originally, everything that is not in WHNF (`exprIsWHNF`) is considered
      a thunk, not eta-expanded, to avoid losing any sharing. This is also how
      the published papers on Call Arity describe it.
      
      In practice, there are thunks that do a just little work, such as
      pattern-matching on a variable, and the benefits of eta-expansion likely
      oughtweigh the cost of doing that repeatedly. Therefore, this
      implementation of Call Arity considers everything that is not cheap
      (`exprIsCheap`) as a thunk.
      
      Nofib reports -2.58% allocations for scs and -40.93% allocation for
      wheel-sieve1; the latter has - 2.92% runtime.
      815099cc
  14. 23 Dec, 2016 4 commits
    • Simon Peyton Jones's avatar
      Propagate evaluated-ness a bit more faithfully · 75e8c305
      Simon Peyton Jones authored
      This was provoked by Trac #13027.
      
      The fix in Simplify actually cures the reported bug; see
      Note [Case binder evaluated-ness] in Simplify.
      
      The fix in CoreTidy looks like an omission that I fixed while I
      was at it.
      75e8c305
    • Simon Peyton Jones's avatar
      Float unboxed expressions by boxing · 432f952e
      Simon Peyton Jones authored
      This patch makes GHC's floating more robust, by allowing it
      to float unboxed expressions of at least some common types.
      
      See Note [Floating MFEs of unlifted type] in SetLevels.
      
      This was all provoked by Trac #12603
      
      In working this through I also made a number of other corner-case
      changes in SetLevels:
      
      * Previously we inconsistently use exprIsBottom (which checks for
        bottom) instead of exprBotStrictness_maybe (which checks for
        bottoming functions).  As well as being inconsistent it was
        simply less good.
      
        See Note [Bottoming floats]
      
      * I fixed a case where were were unprofitably floating an
        expression because we thought it escaped a value lambda
        (see Note [Escaping a value lambda]).  The relevant code is
             float_me = (dest_lvl `ltMajLvl` (le_ctxt_lvl env)
                        && not float_is_lam)   -- NEW
      
      * I made lvlFloatRhs work properly in the case where abs_vars
        is non-empty.  It wasn't wrong before, but it did some stupid
        extra floating.
      432f952e
    • Simon Peyton Jones's avatar
      Comments only · 9a4af2c4
      Simon Peyton Jones authored
      9a4af2c4
    • Simon Peyton Jones's avatar
      Alpha-renaming and white space only · 7a13f1f7
      Simon Peyton Jones authored
      7a13f1f7
  15. 21 Dec, 2016 2 commits
    • Simon Peyton Jones's avatar
      Move InId/OutId to CoreSyn · 05d233e8
      Simon Peyton Jones authored
      It turned out that many different modules defined the same type
      synonyms (InId, OutId, InType, OutType, etc) for the same purpose.
      
      This patch is refactoring only: it moves all those definitions to
      CoreSyn.
      05d233e8
    • Simon Peyton Jones's avatar
      Don't eta-expand in stable unfoldings · e07ad4db
      Simon Peyton Jones authored
      See SimplUtils Note [No eta expansion in stable unfoldings],
      and Trac #9509 for an excellend diagnosis by Nick Frisby
      e07ad4db
  16. 20 Dec, 2016 1 commit
  17. 19 Dec, 2016 1 commit
  18. 18 Dec, 2016 1 commit
  19. 16 Dec, 2016 1 commit
  20. 13 Dec, 2016 1 commit
  21. 12 Dec, 2016 2 commits
    • Simon Peyton Jones's avatar
      Float unboxed expressions by boxing · bc3d37da
      Simon Peyton Jones authored
      This patch makes GHC's floating more robust, by allowing it
      to float unboxed expressions of at least some common types.
      
      See Note [Floating MFEs of unlifted type] in SetLevels.
      
      This was all provoked by Trac #12603
      bc3d37da
    • Simon Peyton Jones's avatar
      Fix a long-standing bug in CSE · d03dd237
      Simon Peyton Jones authored
      I had the environments wrong so that CSE could mis-clone
      an expression, if the uniques just happened to be badly
      arranged.  It's hard to trigger the bug, so I can't make
      a reliable test case.
      
      Happily the fix is easy.
      d03dd237
  22. 11 Dec, 2016 1 commit
    • Moritz Angermann's avatar
      Make globals use sharedCAF · c3c70244
      Moritz Angermann authored
      Summary:
      The use of globals is quite painful when multiple rts are loaded, e.g.
      when plugins are loaded, which bring in a second rts. The sharedCAF
      appraoch was employed for the FastStringTable; I've taken the libery
      to extend this to the other globals I could find.
      
      This is a reboot of D2575, that should hopefully not exhibit the same
      windows build issues.
      
      Reviewers: Phyx, simonmar, goldfire, bgamari, austin, hvr, erikd
      
      Reviewed By: Phyx, simonmar, bgamari
      
      Subscribers: mpickering, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2773
      c3c70244
  23. 09 Dec, 2016 1 commit
    • Sylvain Henry's avatar
      Scrutinee Constant Folding · d3b546b1
      Sylvain Henry authored
      This patch introduces new rules to perform constant folding through
      case-expressions.
      
      E.g.,
      ```
      case t -# 10# of _ {  ===> case t of _ {
               5#      -> e1              15#     -> e1
               8#      -> e2              18#     -> e2
               DEFAULT -> e               DEFAULT -> e
      ```
      
      The initial motivation is that it allows "Merge Nested Cases"
      optimization to kick in and to further simplify the code
      (see Trac #12877).
      
      Currently we recognize the following operations for Word# and Int#: Add,
      Sub, Xor, Not and Negate (for Int# only).
      
      Test Plan: validate
      
      Reviewers: simonpj, austin, bgamari
      
      Reviewed By: simonpj, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D2762
      
      GHC Trac Issues: #12877
      d3b546b1
  24. 05 Dec, 2016 1 commit
    • Simon Peyton Jones's avatar
      Fix an asymptotic bug in the occurrence analyser · 517d03e4
      Simon Peyton Jones authored
      Trac #12425 and #12234 showed up a major and long-standing
      bug in the occurrence analyser, whereby it could generate
      explonentially large program!
      
      There's a lot of commentary on #12425; and it's all described
      in Note [Loop breakers, node scoring, and stability]
      
      I did quite a lot of refactoring to make the code comprehensibe
      again (its structure had bit-rotted rather), so the patch
      looks bigger than it really is.
      
      Hurrah!
      
      I did a nofib run to check that I hadn't inadertently ruined
      anything:
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
      --------------------------------------------------------------------------------
                fluid          -0.3%     -1.5%      0.01      0.01     +0.0%
               parser          -0.9%     +0.6%      0.04      0.04     +0.0%
               prolog          -0.1%     +1.2%      0.00      0.00     +0.0%
      
      --------------------------------------------------------------------------------
                  Min          -0.9%     -1.5%     -8.6%     -8.7%     +0.0%
                  Max          +0.1%     +1.2%     +7.7%     +7.8%     +2.4%
       Geometric Mean          -0.2%     -0.0%     -0.2%     -0.3%     +0.0%
      
      I checked what happened in 'prolog'.  It seems that we have a
      recursive data structure something like this
      
         f :: [blah]
         f x = build (\cn.  ...g...  )
      
         g :: [blah2]
         g y = ....(foldr k z (f y))....
      
      If we inline 'f' into 'g' we get better fusion than the other
      way round, but we don't have any way to spot that at the moment.
      (I wonder if we could do worker/wrapper for functions returning
      a 'build'?)  It was happening before by a fluke.
      
      Anyway I decided to accept this; it's relatively rare I think.
      517d03e4
  25. 01 Dec, 2016 1 commit
  26. 30 Nov, 2016 1 commit
  27. 29 Nov, 2016 1 commit
    • Moritz Angermann's avatar
      Make globals use sharedCAF · 6f7ed1e5
      Moritz Angermann authored
      The use of globals is quite painful when multiple rts are loaded, e.g.
      when plugins are loaded, which bring in a second rts. The sharedCAF
      appraoch was employed for the FastStringTable; I've taken the libery
      to extend this to the other globals I could find.
      
      Reviewers: rwbarton, simonmar, austin, hvr, erikd, bgamari
      
      Reviewed By: simonmar, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D2575
      6f7ed1e5
  28. 28 Nov, 2016 1 commit