1. 08 Feb, 2017 15 commits
    • Ben Gamari's avatar
      Generalize CmmUnwind and pass unwind information through NCG · 3eb737ee
      Ben Gamari authored
      As discussed in D1532, Trac Trac #11337, and Trac Trac #11338, the stack
      unwinding information produced by GHC is currently quite approximate.
      Essentially we assume that register values do not change at all within a
      basic block. While this is somewhat true in normal Haskell code, blocks
      containing foreign calls often break this assumption. This results in
      unreliable call stacks, especially in the code containing foreign calls.
      This is worse than it sounds as unreliable unwinding information can at
      times result in segmentation faults.
      
      This patch set attempts to improve this situation by tracking unwinding
      information with finer granularity. By dispensing with the assumption of
      one unwinding table per block, we allow the compiler to accurately
      represent the areas surrounding foreign calls.
      
      Towards this end we generalize the representation of unwind information
      in the backend in three ways,
      
       * Multiple CmmUnwind nodes can occur per block
      
       * CmmUnwind nodes can now carry unwind information for multiple
         registers (while not strictly necessary; this makes emitting
         unwinding information a bit more convenient in the compiler)
      
       * The NCG backend is given an opportunity to modify the unwinding
         records since it may need to make adjustments due to, for instance,
         native calling convention requirements for foreign calls (see
         #11353).
      
      This sets the stage for resolving #11337 and #11338.
      
      Test Plan: Validate
      
      Reviewers: scpmw, simonmar, austin, erikd
      
      Subscribers: qnikst, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2741
      3eb737ee
    • Simon Peyton Jones's avatar
      Improve -dsuppress-coercions · 421308ef
      Simon Peyton Jones authored
      The -dsuppress-coercions flag was being ignored when printing the
      CastIt constructor in SimplUtils.SimplCont.  This fixes ths problem,
      and improves what is printed when suppressing coercions, to show the
      size of the suppressed coercion.
      421308ef
    • Simon Peyton Jones's avatar
      Improve the simple optimiser · 8e9593fb
      Simon Peyton Jones authored
      The previous version of the simple optimiser would leave
      beta-redexes, which was bad for join points.  E.g.
      
        join j x = ....   -- a join point
        in (\x. j x) y
      
      This would be ok if we beta-reduced the (\x) but not if
      we don't.
      
      This patch improves the simple optimiser, to follow the plan
      described in "Secrets of the GHC inliner", and implemented in
      the Mighty Simplifier.  It turns out not to be too hard to
      use the same plan here, and we get slightly better code as
      a result.
      8e9593fb
    • Gabor Greif's avatar
      More typos in comments [skip ci] · b990f656
      Gabor Greif authored
      b990f656
    • Ben Gamari's avatar
      Update hoopl submodule · 512f157c
      Ben Gamari authored
      This is in preparation for an upcoming bump of the containers submodule.
      512f157c
    • Matthew Pickering's avatar
      Pass -v0 to ghc-pkg to reduce noise in build ouput · 015e97af
      Matthew Pickering authored
      By default ghc-pkg is quite noisy as it can't find interface files.
      
      Test Plan:
      Look at the build log stderr and see if there are lots of "cannot find
      any of" errors.
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie, snowleopard
      
      Differential Revision: https://phabricator.haskell.org/D3103
      015e97af
    • Takenobu Tani's avatar
      Fix comment (broken link to users_guide) in $(TOP)/ · db3a797a
      Takenobu Tani authored
      There was a broken link to users_guide at a comment.
      
      * compiler/types/InstEnv.hs
        - type-class-extensions.html -> glasgow_exts.html
      
      Reviewers: bgamari, austin
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3092
      db3a797a
    • Takenobu Tani's avatar
      Fix comment of `section "Exceptions"` · 3e071261
      Takenobu Tani authored
      I changed comment from `{- .. -}` to `--`.
      Because Haddock comment for `section "Exceptions"` [1] was broken.
      
      [1]:
      https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc-prim-0
      .5.0.0/GHC-Prim.html
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3083
      3e071261
    • Matthew Pickering's avatar
      Fix push_bang_into_newtype when the pattern match has no arguments · 062f1123
      Matthew Pickering authored
      Correct behaviour of push_bang_into_newtype when the pattern match has
      no arguments. A user can write
      
      ```
      newtype T = T Int
      
      f :: T -> ()
      f !(T {}) = ()
      ```
      in which case we have to push the bang inwards through the newtype in
      order to achieve the desired strictness properties. This patch fixes
      this special case where the pattern match has no arguments to push the
      bang onto. We now make up a wildcard pattern which is wrapped in the
      bang pattern.
      
      ```
      f (T !_) = ()
      ```
      
      Reviewers: simonpj, austin, bgamari
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3057
      062f1123
    • Ben Gamari's avatar
      Update Core formalize for Levity -> RuntimeRep · bc376d32
      Ben Gamari authored
      Reviewers: austin
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3094
      bc376d32
    • Ben Gamari's avatar
      cpeApp: Make Int accumulator strict · 8c25be80
      Ben Gamari authored
      Test Plan: Validate
      
      Reviewers: austin, dfeuer
      
      Subscribers: dfeuer, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3093
      8c25be80
    • Ben Gamari's avatar
      testsuite: Bump bytes allocated for T5837 · 0aa3f8d4
      Ben Gamari authored
      Simon decreased this earlier today but Harbormaster doesn't reproduce his
      number. I've done two things here:
      
       1. increased the allocations number to the Harbormaster value
       2. increased the acceptance threshold from 5% to 7%, since Simon saw a 6.6%
          change in his environment.
      0aa3f8d4
    • Ben Gamari's avatar
      testsuite: Bump max_bytes_used for T4029 · 369c534f
      Ben Gamari authored
      Unfortunately it's not clear what regressed this.
      369c534f
    • David Feuer's avatar
      Clean up findPartiallyCompletedCycles · e90f611d
      David Feuer authored
      Rewrite `findPartiallyCompletedCycles` to use a list comprehension
      rather than pattern matching on a list. Make it use `Data.Set`
      rather than fussing with lists.
      
      Reviewers: austin, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3102
      e90f611d
    • David Feuer's avatar
      Use better map operations in CoreMonad · d5e9b7f5
      David Feuer authored
      Use strict `unionWith` where apparently appropriate, and use
      strict `insertWith` rather than lookup followed by insertion.
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3099
      d5e9b7f5
  2. 07 Feb, 2017 7 commits
    • Siddhanathan Shanmugam's avatar
    • Daniel Gröber (dxld)'s avatar
      Docs: Fix typo in glasgow_exts.rst · 078beea9
      Daniel Gröber (dxld) authored
      078beea9
    • Simon Peyton Jones's avatar
      Another improvement to SetLevels · b8f58d79
      Simon Peyton Jones authored
      In my recent commit
         commit 432f952e
         Float unboxed expressions by boxing
      I changed how float_me in lvlMFE worked.  That was right, but
      it exposed another bug: an error expression wasn't getting floated
      as it should from a case alternative.  And that led to a collection
      of minor improvements
      
      * I found a much better way to cast it, by using lvlFloatRhs for
        top-level bindinds as well as nested ones, which is
          (a) more consistent and
          (b) works correctly.
      
        See Note [Floating from a RHS]
      
      * I also found some delicacy in the "floating to the top" stuff, so I
        greatly elaborated the Note [Floating to the top].
      
      * I simplified the "bottoming-float" stuff; the change is in the treatment
        of bottoming lambdas (\x y. error blah), where we now float the
        (error blah) part instead of the whole lambda (which risks just making
        duplicate lambdas.  See Note [Bottoming floats], esp (2).
      
      Perf effects are minor.
      
      * perf/compiler/T13056 improved sligtly (about 2%) in compiler
        allocations. Also T9233 improved by 1%.  I'm not sure why.
      
      * Some small nofib changes:
          - Generally some very small reductions in run-time
            allocation, except k-nucleotide, which halves for some
            reason.  (I did try to look but it's a big complicated
            function and it was far from obvious.  Had it been a loss
            I would have looked harder!
      
      NB: there's a nearby patch "Do not inline bottoming things" that could
      also be responsible for either or both.  I didn't think it was worth
      more testing to distinguish.
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs   Runtime   Elapsed  TotalMem
      --------------------------------------------------------------------------------
                 grep          +0.1%     -0.2%      0.00      0.00     +0.0%
               mandel          -0.1%     -1.4%      0.13      0.13     +0.0%
         k-nucleotide          +0.1%    -51.6%     -1.0%     -1.0%     +0.0%
      --------------------------------------------------------------------------------
                  Min          -0.3%    -51.6%     -9.4%     -9.1%     -4.0%
                  Max          +0.2%     +0.0%    +31.8%    +32.7%     +0.0%
       Geometric Mean          -0.0%     -0.8%     +1.4%     +1.4%     -0.1%
      b8f58d79
    • Simon Peyton Jones's avatar
      Comments only · f77e99bb
      Simon Peyton Jones authored
      f77e99bb
    • Simon Peyton Jones's avatar
      Do not inline bottoming things · a0174d22
      Simon Peyton Jones authored
      If a function seems small, worker/wrapper won't split it; instead
      it turns it into an INLINE function.
      
      But if it's a /bottoming/ function that's a bad idea.  We want
      don't want to inline bottoming functions unless they are /really/
      small (smaller than the call itself) and that's handled by a
      different branch in certainlyWillInline.
      
      So this patch adds a not-bottom test to the UnfIfGoodArgs case of
      certainlyWillInline.
      
      No big perf effect, but this will tend to keep error code out of
      functions, and hence make them a bit more likely to inline.
      
      I fell over this when fiddling with #13144
      a0174d22
    • Gabor Greif's avatar
      Typos in comments [skip ci] · 17ae5e79
      Gabor Greif authored
      17ae5e79
    • David Feuer's avatar
      Derive <$ · 2219c8cd
      David Feuer authored
      Using the default definition of `<$` for derived `Functor`
      instance is very bad for recursive data types. Derive
      the definition instead.
      
      Fixes #13218
      
      Reviewers: austin, bgamari, RyanGlScott
      
      Reviewed By: RyanGlScott
      
      Subscribers: RyanGlScott, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3072
      2219c8cd
  3. 06 Feb, 2017 12 commits
    • Ryan Scott's avatar
      Remove unnecessary use of -DGENERICS flag · a28a5521
      Ryan Scott authored
      This flag was only needed for old versions of binary, and now that we've
      upgraded to binary-0.8.4.1, it is no longer necessary.
      a28a5521
    • Gabor Greif's avatar
      Typos in comments [skip ci] · 4aae1918
      Gabor Greif authored
      4aae1918
    • Gabor Greif's avatar
      Typos in comments [skip ci] · 2dff54b3
      Gabor Greif authored
      2dff54b3
    • Eric Seidel's avatar
      Do Worker/Wrapper for NOINLINE things · b572aadb
      Eric Seidel authored
      Disabling worker/wrapper for NOINLINE things can cause unnecessary
      reboxing of values. Consider
      
          {-# NOINLINE f #-}
          f :: Int -> a
          f x = error (show x)
      
          g :: Bool -> Bool -> Int -> Int
          g True  True  p = f p
          g False True  p = p + 1
          g b     False p = g b True p
      
      the strictness analysis will discover f and g are strict, but because f
      has no wrapper, the worker for g will rebox p. So we get
      
          $wg x y p# =
            let p = I# p# in  -- Yikes! Reboxing!
            case x of
              False ->
                case y of
                  False -> $wg False True p#
                  True -> +# p# 1#
              True ->
                case y of
                  False -> $wg True True p#
                  True -> case f p of { }
      
          g x y p = case p of (I# p#) -> $wg x y p#
      
      Now, in this case the reboxing will float into the True branch, an so
      the allocation will only happen on the error path. But it won't float
      inwards if there are multiple branches that call (f p), so the reboxing
      will happen on every call of g. Disaster.
      
      Solution: do worker/wrapper even on NOINLINE things; but move the
      NOINLINE pragma to the worker.
      
      Test Plan: make test TEST="13143"
      
      Reviewers: simonpj, bgamari, dfeuer, austin
      
      Reviewed By: simonpj, bgamari
      
      Subscribers: dfeuer, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3046
      b572aadb
    • Ben Gamari's avatar
      a9754e3c
    • lukemaurer's avatar
      Fixes for OccurAnal bugs (#13221) · 795bc49c
      lukemaurer authored
      - OccurAnal: When checking tail calls, count rule's LHS args, not bndrs
      Pretty obvious error in retrospect:
      ```
      let $sj = \y ys -> ...
          {-# RULES "SC:j" forall y ys. j (y:ys) = $sj y ys #-}
          j = \xs -> ...
          in ...
      ```
      A jump on the RHS of a rule for a join point is only okay if the rule's
      LHS is
      saturated - in this case, since the LHS is j (y:ys) and j takes one
      argument,
      both j and $sj can become join points. See Note [Rules and join points]
      in
      OccurAnal. By mistake, OccAnal was counting the rule's binders (y and
      ys) rather
      than the args in its LHS, so $sj wasn't being made a join point.
      
      - Don't zap tail calls in unfoldings
      
      This was causing T7796 to squeal about join points not being
      rediscovered.
      
      Reviewers: bgamari, austin
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3080
      795bc49c
    • Takenobu Tani's avatar
      Fix broken link of GHC.RTS.Flags · 563148cd
      Takenobu Tani authored
      There ware broken link to GHC User's Guide.
      
      * libraries/base/GHC/RTS/Flags.hsc
       - runtime-control.html -> runtime_control.html
      
      Reviewers: bgamari, austin, hvr
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3084
      563148cd
    • Takenobu Tani's avatar
      Fix comment (old file names '.hc' ) in libraries/ · 26f5e60b
      Takenobu Tani authored
      There ware some old file names (.hc, ...) at comments.
      
      * libraries/base/GHC/IO.hs
        - StgMiscClosures.hc -> StgStartup.cmm
        - Exceptions.hc -> Exception.cmm
        - Schedule.c -> RaiseAsync.c
      
      A comment of `(un)?blockAsyncExceptionszh_fast` in IO.hs may be old.
      Since I don't understand it, I have not modified it yet.
      
      Reviewers: mpickering, bgamari, austin, hvr
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3081
      26f5e60b
    • Matthew Pickering's avatar
      Don't return empty initial uncovered set for an unsat context · adb565aa
      Matthew Pickering authored
      Previously when the checker encountered an unsatisfiable term of type
      context it would return an empty initial uncovered set. This caused all
      pattern matches in the context to be reported as redudant.
      
      This is arguably correct behaviour as they will never be reached but it
      is better to recover and provide accurate warnings for these cases to
      avoid error cascades. It would perhaps be better to report an error to
      the user about an inacessible branch but this is certainly better than
      many confusing redundant match warnings.
      
      Reviewers: gkaracha, austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3064
      adb565aa
    • rwbarton's avatar
      Don't replace type family instances with the same LHS in GHCi (#7102) · 0abe7361
      rwbarton authored
      This fixes the easy part of #7102 by removing the logic that lets the
      user replace a type family instance with a new one with the same LHS.
      As discussed on that ticket, this is unsound in general. Better to have
      the user redefine the type family from scratch.
      
      The example from comment:7 involving loading modules into ghci is not
      fixed yet; it actually doesn't rely on the instances having the same LHS.
      This commit adds an expect_broken test for that example as well.
      
      Test Plan: T7102a for the fix; T7102 is the test not fixed yet
      
      Reviewers: dfeuer, austin, bgamari, goldfire
      
      Reviewed By: dfeuer
      
      Subscribers: dfeuer, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2994
      0abe7361
    • alexbiehl's avatar
      Use proper primitives in Utils.Binary · fbcef83a
      alexbiehl authored
      `Word{16,32,64}` are implemented using `getWord8`. This patch introduces
      `getWord{16,32,64}` and `putWord{16,32,64}`. This is nicer and
      probably a bit faster.
      
      Reviewers: bgamari, austin
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D2908
      fbcef83a
    • David Feuer's avatar
      Add liftA2 to Applicative class · a2f39da0
      David Feuer authored
      * Make `liftA2` a method of `Applicative`.
      
      * Add explicit `liftA2` definitions to instances in `base`.
      
      * Add explicit invocations in `base`.
      
      Reviewers: ekmett, bgamari, RyanGlScott, austin, hvr
      
      Reviewed By: RyanGlScott
      
      Subscribers: ekmett, RyanGlScott, rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3031
      a2f39da0
  4. 04 Feb, 2017 6 commits