1. 12 Feb, 2017 12 commits
    • Niklas Hambüchen's avatar
      bufWrite: Save extra syscall when data fills handle buffer completely. · 6b4e46a1
      Niklas Hambüchen authored
      The bug is that the check `if (size - w > count)` should be
      `if (size - w >= count)` instead (`>=` instead of `>`),
      because we can do the write all fine if it fits exactly.
      This allows us to do 1 instead of 2 write syscalls the case it fits.
      An example of when this matters is when an application writes output
      in chunks that are a fraction of the handle buffer size.
      For example, assume the buffer size is 8 KB, and the application writes
      four 2 KB chunks.
      Until now, this would result in 3 copies to the handle buffer, but
      the 4th one would not be allowed in by `size - w > count`
      (because `size - w == count` is the case), so we'd end up with a write
      syscall of only 6 KB data instead of 8 KB, thus creating more syscalls
      Implementing this fix (switching to `size - w >= count`), we also have
      to flush the buffer if we fill it completely.
      If we made only the changes described so far, that would have the
      unintended side effect that writes of the size equal to the handle
      buffer size (`count == size`) suddenly also go to the handle buffer
      first: The data would first be copied to the handle buffer, and then
      immediately get flushed to the underlying FD.  We don't want that extra
      `memcpy`, because it'd be unnecessary: The point of handle buffering is
      to coalesce smaller writes, and there are no smaller writes in this
      case.  For example, if you specify 8 KB buffers (which menas you want
      your data to be written out in 8 KB blocks), and you get data that's
      already 8 KB in size, you can write that out as an 8 KB straight away,
      zero-copy fashion.  For this reason, adding to the handle buffer now got
      an additional condition `count < size`.  That way, writes equal to the
      buffer size go straight to the FD, as they did before this commit.
      Reviewers: simonmar, austin, hvr, bgamari
      Reviewed By: simonmar
      Subscribers: mpickering, thomie
      Differential Revision: https://phabricator.haskell.org/D3117
    • Niklas Hambüchen's avatar
      Fix: hPutBuf issues unnecessary empty write syscalls for large writes (#13246) · 805db965
      Niklas Hambüchen authored
      Until now, any `hPutBuf` that wrote `>= the handle buffer size` would
      trigger an unnecessary `write("")` system call before the actual write
      system call.
      This is fixed by making sure that we never flush an empty handle buffer:
      Only flush `when (w > 0)`.
      Reviewers: simonmar, austin, hvr, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3119
    • Niklas Hambüchen's avatar
      Fix: Default FD buffer size is not a power of 2 (#13245) · 4e2e9b73
      Niklas Hambüchen authored
      Reviewers: simonmar, austin, hvr, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3115
    • David Feuer's avatar
      Avoid repeated list elem checks · 7938ef23
      David Feuer authored
      Convert a list to a set before testing membership multiple times.
      Reviewers: austin, bgamari
      Reviewed By: bgamari
      Subscribers: rwbarton, thomie
      Differential Revision: https://phabricator.haskell.org/D3111
    • alexbiehl's avatar
      Binary: Only allocate un-interned FastStrings · 64da671a
      alexbiehl authored
      Test Plan: Validate
      Reviewers: austin, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3109
    • Christiaan Baaij's avatar
      zonkCt tries to maintain the canonical form of a Ct. · 07292e95
      Christiaan Baaij authored
      For example,
       - a CDictCan should stay a CDictCan;
       - a CTyEqCan should stay a CTyEqCan (if the LHS stays as a variable.).
       - a CHoleCan should stay a CHoleCan
      Why?  For CDicteqCan see Trac #11525.
      Test Plan: Validate
      Reviewers: austin, adamgundry, simonpj, goldfire, bgamari
      Reviewed By: simonpj, bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3105
    • Ben Gamari's avatar
      rts/Profiling: Factor out report generation · 56c9bb39
      Ben Gamari authored
      Here we move the actual report generation logic to
      `rts/ProfilerReport.c`. This break is actually quite clean,
          void writeCCSReport( FILE *prof_file, CostCentreStack const *ccs,
                               ProfilerTotals totals );
      This is more profiler refactoring in preparation for machine-readable
      Test Plan: Validate
      Reviewers: austin, erikd, simonmar
      Reviewed By: simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3097
    • Ben Gamari's avatar
      rts/Profiling: Kill a few globals and add consts · 1a14d384
      Ben Gamari authored
      Previously it was quite difficult to follow the dataflow through this
      file due to global mutation and rather non-descriptive types.
      This is a cleanup in preparation for factoring out the report-generating
      logic, which is itself in preparation for somedayteaching the profiler
      to produce more machine-readable reports (JSON perhaps?).
      Test Plan: Validate
      Reviewers: austin, erikd, simonmar
      Reviewed By: simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3096
    • Edward Z. Yang's avatar
      Fix #13214 by correctly setting up dep_orphs for signatures. · 26eaa7ec
      Edward Z. Yang authored
      Prior to this, I hadn't thought about orphan handling at all.
      This commit implements the semantics that if a signature
      (transitively) imports an orphan instance, that instance
      is considered in scope no matter what the implementing module
      is.  (As it turns out, this is the semantics that falls out
      when orphans are recorded transitively.)
      This patch fixes a few bugs:
      1. Put semantic modules in dep_orphs rather than identity
      2. Don't put the implementing module in dep_orphs when
         merging signatures (this is a silly bug that happened
         because we were reusing calculateAvails, which is
         designed for imports. It mostly works for signature
         merging, except this case.)
      3. When renaming a signature, blast in the orphans of the
         implementing module inside Dependencies.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      Test Plan: validate
      Reviewers: bgamari, austin
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3095
    • Joachim Breitner's avatar
      Improve the Occurrence Analyzer’s handling of one-shot functions · a1980ecb
      Joachim Breitner authored
      When determining whether an expression is used saturatedly, count the
      number of value arguments that the occurrence analyser sees, and add
      the number of one-shot arguments that we know (from the strictness
      analyser) are passed from the context.
      perf results suggest no noticable change in allocations, reduction of
      code sizes, and performance regression possibliy due to loss of join
      Test Plan: perf.haskell.org
      Reviewers: simonpj, austin, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3089
    • rwbarton's avatar
      Mark orphan instances and rules in --show-iface output · 17b1e0ba
      rwbarton authored
      Test Plan: new test Orphans
      Reviewers: austin, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3086
    • Ben Gamari's avatar
      Dwarf.Types: Use DW_CFA_same_value encoding when possible · 7fac7cdc
      Ben Gamari authored
      This is a bit smaller than the alternative, DW_CFA_val_expression. Also
      a bit of refactoring.
      Test Plan: Validate
      Reviewers: scpmw, simonmar, austin
      Reviewed By: simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D2745
  2. 11 Feb, 2017 1 commit
  3. 10 Feb, 2017 6 commits
    • Ryan Scott's avatar
      Refactor DeriveAnyClass's instance context inference · 639e702b
      Ryan Scott authored
      Currently, `DeriveAnyClass` has two glaring flaws:
      * It only works on classes whose argument is of kind `*` or `* -> *` (#9821).
      * The way it infers constraints makes no sense. It basically co-opts the
        algorithms used to infer contexts for `Eq` (for `*`-kinded arguments) or
        `Functor` (for `(* -> *)`-kinded arguments). This tends to produce overly
        constrained instances, which in extreme cases can lead to legitimate things
        failing to typecheck (#12594). Or even worse, it can trigger GHC panics
        (#12144 and #12423).
      This completely reworks the way `DeriveAnyClass` infers constraints to fix
      these two issues. It now uses the type signatures of the derived class's
      methods to infer constraints (and to simplify them). A high-level description
      of how this works is included in the GHC users' guide, and more technical notes
      on what is going on can be found as comments (and a Note) in `TcDerivInfer`.
      Fixes #9821, #12144, #12423, #12594.
      Test Plan: ./validate
      Reviewers: dfeuer, goldfire, simonpj, austin, bgamari
      Subscribers: dfeuer, thomie
      Differential Revision: https://phabricator.haskell.org/D2961
    • Facundo Domínguez's avatar
      Relax test TH_addCStub2 so it succeeds on travis. · e79ef75d
      Facundo Domínguez authored
      Test Plan: ./validate
      Reviewers: bgamari, nomeata, austin, mpickering
      Reviewed By: mpickering
      Subscribers: mpickering, rwbarton, mboes, thomie
      Differential Revision: https://phabricator.haskell.org/D3124
    • Ryan Scott's avatar
      Prevent Template Haskell splices from throwing a spurious TypeInType error · 283a3465
      Ryan Scott authored
      There was a rather annoying corner case where splicing poly-kinded
      Template Haskell declarations could trigger an error muttering about
      `TypeInType` not being enabled, whereas the equivalent non-TH code would
      compile without issue. This was causing by overzealous validity check in the
      renamer, wherein failed to distinguish between two different `Exact` names
      with the same `OccName`. As a result, it mistakenly believed some type
      variables were being used as both type and kind variables simultaneously! Ack.
      This avoids the issue by simply disabling the aforementioned validity check
      for Exact names. Fixes #12503.
      Test Plan: ./validate
      Reviewers: austin, bgamari, goldfire
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3022
    • Simon Peyton Jones's avatar
      Change rewritableTyVarsOfType to anyRewritableTyVar · 76244ec2
      Simon Peyton Jones authored
      This fixes the regression in FrozenErrorTests, eliminates the
      awkward "crash on forall" in rewritableTyVars, and makes it more
      efficient too.
    • Gabor Greif's avatar
      Spelling in comments [ci skip] · 3211fa06
      Gabor Greif authored
    • Alan Zimmerman's avatar
      TH-spliced class instances are pretty-printed incorrectly post-#3384 · 258c7195
      Alan Zimmerman authored
      The HsSyn prettyprinter tests patch 499e4382
      broke the pretty-printing of Template Haskell-spliced class instances.
      Test Plan: ./validate
      Reviewers: RyanGlScott, austin, goldfire, bgamari
      Reviewed By: RyanGlScott, bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3043
  4. 09 Feb, 2017 9 commits
  5. 08 Feb, 2017 12 commits
    • Ben Gamari's avatar
    • Alan Zimmerman's avatar
      Add dump flags for the renamed and typechecked hsSyn ASTs · 7e4e6a73
      Alan Zimmerman authored
      D2958 brought in the "dump-parsed-ast" functionality.
      Extend it to include "dump-rn-ast" and "dump-tc-ast"
      Test Plan: ./validate
      Reviewers: austin, bgamari
      Reviewed By: bgamari
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3107
    • Simon Peyton Jones's avatar
      Back-pedal the fix for Trac #8155 · a94b4847
      Simon Peyton Jones authored
      I implemented a rather elaborate fix for #8155 ages ago, which
      which turns out to be
        a) unnecesssary in this particular case
        b) harmful to the defaulting story; see comment:15 of #12923.
      So this patch reverts the elaborate bit. The bit I removed is
      described in "Historical note" under Note [approximateWC].
    • Simon Peyton Jones's avatar
      Kill inaccessible-branch complaints in record update · 3cfef763
      Simon Peyton Jones authored
      Trac #12957 (the original case in the Description) showed a record
      update that yielded an "inaccessible code" warning. This should not
      happen; it's just some redundant code generated by the desugarer (later
      pruned away) and it's not the user's fault.
      This patch suppresses the warning.  See Check.hs
      Note [Inaccessible warnings for record updates]
    • Simon Peyton Jones's avatar
    • Ben Gamari's avatar
      Fix stop_thread unwinding information · 34e35233
      Ben Gamari authored
      This corrects the unwind information for `stg_stop_thread`, which
      allows us to unwind back to the C stack after reaching the end of the 
      STG stack.
      Test Plan: Validate
      Reviewers: simonmar, austin, erikd
      Reviewed By: simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D2746
    • Ben Gamari's avatar
      CmmLayoutStack: Correctly annotate Sp adjustments with unwinding information · 5279b08b
      Ben Gamari authored
      Test Plan: Validate
      Reviewers: austin, simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D3104
    • Ben Gamari's avatar
      Cmm: Add support for undefined unwinding statements · 3328ddb8
      Ben Gamari authored
      And use to mark `stg_stack_underflow_frame`, which we are unable to
      determine a caller from.
      To simplify parsing at the moment we steal the `return` keyword to
      indicate an undefined unwind value. Perhaps this should be revisited.
      Reviewers: scpmw, simonmar, austin, erikd
      Subscribers: dfeuer, thomie
      Differential Revision: https://phabricator.haskell.org/D2738
    • Ben Gamari's avatar
      CmmLayoutStack: Add unwind information on stack fixups · 733e845d
      Ben Gamari authored
      Currently stack fixup blocks don't include unwinding information,
      leaving a small window where our unwinding information is incorrect. Fix
      this by adding unwinding information to emitted fixup blocks.
      Reviewers: scpmw, simonmar, austin
      Reviewed By: simonmar
      Subscribers: thomie
      Differential Revision: https://phabricator.haskell.org/D2742
    • 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
      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
    • 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.
    • 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.