1. 08 Nov, 2017 2 commits
    • Simon Peyton Jones's avatar
      Minimise provided dictionaries in pattern synonyms · 2c2f3cea
      Simon Peyton Jones authored
      Trac #14394 showed that it's possible to get redundant
      constraints in the inferred provided constraints of a pattern
      synonym.  This patch removes the redundancy with mkMinimalBySCs.
      
      To do this I had to generalise the type of mkMinimalBySCs slightly.
      And, to reduce confusing reversal, I made it stable: it now returns
      its result in the same order as its input.  That led to a raft of
      error message wibbles, mostly for the better.
      2c2f3cea
    • Simon Peyton Jones's avatar
      Fix another dark corner in the shortcut solver · 30058b0e
      Simon Peyton Jones authored
      The shortcut solver for type classes (Trac #12791) was eagerly
      solving a constaint from an OVERLAPPABLE instance. It happened
      to be the only one in scope, so it was unique, but since it's
      specfically flagged as overlappable it's really a bad idea to
      solve using it, rather than using the Given dictionary.
      
      This led to Trac #14434, a nasty and hard to identify bug.
      30058b0e
  2. 07 Nov, 2017 3 commits
  3. 06 Nov, 2017 2 commits
  4. 03 Nov, 2017 1 commit
  5. 02 Nov, 2017 4 commits
  6. 30 Oct, 2017 3 commits
    • Gabor Greif's avatar
      Fix typo in accessor name · 1b115b16
      Gabor Greif authored
      and in comments
      1b115b16
    • Michal Terepeta's avatar
      Allow packing constructor fields · cca2d6b7
      Michal Terepeta authored
      This is another step for fixing #13825
      
       and is based on D38 by Simon
      Marlow.
      
      The change allows storing multiple constructor fields within the same
      word. This currently applies only to `Float`s, e.g.,
      ```
      data Foo = Foo {-# UNPACK #-} !Float {-# UNPACK #-} !Float
      ```
      on 64-bit arch, will now store both fields within the same constructor
      word. For `WordX/IntX` we'll need to introduce new primop types.
      
      Main changes:
      
      - We now use sizes in bytes when we compute the offsets for
        constructor fields in `StgCmmLayout` and introduce padding if
        necessary (word-sized fields are still word-aligned)
      
      - `ByteCodeGen` had to be updated to correctly construct the data
        types. This required some new bytecode instructions to allow pushing
        things that are not full words onto the stack (and updating
        `Interpreter.c`). Note that we only use the packed stuff when
        constructing data types (i.e., for `PACK`), in all other cases the
        behavior should not change.
      
      - `RtClosureInspect` was changed to handle the new layout when
        extracting subterms. This seems to be used by things like `:print`.
        I've also added a test for this.
      
      - I deviated slightly from Simon's approach and use `PrimRep` instead
        of `ArgRep` for computing the size of fields.  This seemed more
        natural and in the future we'll probably want to introduce new
        primitive types (e.g., `Int8#`) and `PrimRep` seems like a better
        place to do that (where we already have `Int64Rep` for example).
        `ArgRep` on the other hand seems to be more focused on calling
        functions.
      Signed-off-by: Michal Terepeta's avatarMichal Terepeta <michal.terepeta@gmail.com>
      
      Test Plan: ./validate
      
      Reviewers: bgamari, simonmar, austin, hvr, goldfire, erikd
      
      Reviewed By: bgamari
      
      Subscribers: maoe, rwbarton, thomie
      
      GHC Trac Issues: #13825
      
      Differential Revision: https://phabricator.haskell.org/D3809
      cca2d6b7
    • Ryan Scott's avatar
      Fix #14390 by making toIfaceTyCon aware of equality · 85aa1f42
      Ryan Scott authored
      GHC was panicking when pretty-printing a heterogeneous
      equality type constructor (#14390) because the function which
      produced the type constructor, `toIfaceTyCon`, wasn't attaching the
      appropriate `IfaceTyConSort` for equality type constructors, which
      is `IfaceEqualityTyCon`. This is fixed easily enough.
      
      Test Plan: make test TEST=T14390
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #14390
      
      Differential Revision: https://phabricator.haskell.org/D4132
      85aa1f42
  7. 29 Oct, 2017 1 commit
    • Joachim Breitner's avatar
      Implement a dedicated exitfication pass #14152 · 0e953da1
      Joachim Breitner authored
      The idea is described in #14152, and can be summarized: Float the exit
      path out of a joinrec, so that the simplifier can do more with it.
      See the test case for a nice example.
      
      The floating goes against what the simplifier usually does, hence we
      need to be careful not inline them back.
      
      The position of exitification in the pipeline was chosen after a small
      amount of experimentation, but may need to be improved. For example,
      exitification can allow rewrite rules to fire, but for that it would
      have to happen before the `simpl_phases`.
      
      Perf.haskell.org reports these nice performance wins:
      
          Nofib allocations
          fannkuch-redux    78446640  - 99.92%      64560
          k-nucleotide     109466384  - 91.32%    9502040
          simple            72424696  -  5.96%   68109560
      
          Nofib instruction counts
          fannkuch-redux  1744331636  -  3.86% 1676999519
          k-nucleotide    2318221965  -  6.30% 2172067260
          scs             1978470869  -  3.35% 1912263779
          simple           669858104  -  3.38%  647206739
          spectral-norm    186423292  -  5.37%  176411536
      
      Differential Revision: https://phabricator.haskell.org/D3903
      0e953da1
  8. 27 Oct, 2017 1 commit
    • Simon Marlow's avatar
      ApplicativeDo: handle BodyStmt (#12143) · 41f90559
      Simon Marlow authored
      Summary:
      It's simple to treat BodyStmt just like a BindStmt with a wildcard
      pattern, which is enough to fix #12143 without going all the way to
      using `<*` and `*>` (#10892).
      
      Test Plan:
      * new test cases in `ado004.hs`
      * validate
      
      Reviewers: niteria, simonpj, bgamari, austin, erikd
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #12143
      
      Differential Revision: https://phabricator.haskell.org/D4128
      41f90559
  9. 25 Oct, 2017 5 commits
    • Tobias Dammers's avatar
      Factor out readField (#14364) · dbd81f7e
      Tobias Dammers authored
      Improves compiler performance of deriving Read instances, as suggested
      in the issue.
      
      Additionally, we introduce `readSymField`, a companion to `readField`
      that parses symbol-type fields (where the field name is a symbol, e.g.
      `(#)`, rather than an alphanumeric identifier. The decision between
      these two functions is made a compile time, because we already know
      which one we need based on the field name.
      
      Reviewers: austin, hvr, bgamari, RyanGlScott
      
      Reviewed By: bgamari
      
      Subscribers: RyanGlScott, rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D4108
      dbd81f7e
    • Alec Theriault's avatar
      Fix a bug in 'alexInputPrevChar' · 821adee1
      Alec Theriault authored
      The lexer hacks around unicode by squishing any character into a 'Word8'
      and then storing the actual character in its state. This happens at
      'alexGetByte'.
      
      That is all and well, but we ought to be careful that the characters we
      retrieve via 'alexInputPrevChar' also fit this convention.
      
      In fact, #13986 exposes nicely what can go wrong: the regex in the left
      context of the type application rule uses the '$idchar' character set
      which relies on the unicode hack. However, a left context corresponds
      to a call to 'alexInputPrevChar', and we end up passing full blown
      unicode characters to '$idchar', despite it not being equipped to deal
      with these.
      
      Test Plan: Added a regression test case
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #13986
      
      Differential Revision: https://phabricator.haskell.org/D4105
      821adee1
    • Daishi Nakajima's avatar
      Implement `-Wpartial-fields` warning (#7169) · f7f270eb
      Daishi Nakajima authored
      Warning on declaring a partial record selector.
      However, disable warn with field names that start with underscore.
      
      Test Plan: Added 1 test case.
      
      Reviewers: austin, bgamari, simonpj
      
      Reviewed By: bgamari, simonpj
      
      Subscribers: goldfire, simonpj, duog, rwbarton, thomie
      
      GHC Trac Issues: #7169
      
      Differential Revision: https://phabricator.haskell.org/D4083
      f7f270eb
    • Douglas Wilson's avatar
      Fix space leak in BinIface.getSymbolTable · 1c15d8ed
      Douglas Wilson authored
      Replace a call to mapAccumR, which uses linear stack space, with a
      gadget that uses constant space.
      
      Remove an unused parameter from fromOnDiskName.
      
      The tests T1292_imports and T4239 are now reporting imported names in a
      different order. I don't completely understand why, but I presume it is
      because the symbol tables are now read more strictly. The new order
      seems better in T1792_imports, and equally random in T4239.
      
      There are several performance test improvements.
      
      Test Plan: ./validate
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: alexbiehl, rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D4124
      1c15d8ed
    • Ben Gamari's avatar
      typecheck: Clarify errors mentioned in #14385 · bf83435b
      Ben Gamari authored
      bf83435b
  10. 24 Oct, 2017 1 commit
    • Simon Peyton Jones's avatar
      Temporary fix to Trac #14380 · d1eaeadb
      Simon Peyton Jones authored
      This fix replaces an utterly bogus error message with a decent one,
      rejecting a pattern synonym with a list pattern and rebindable syntax.
      
      Not hard to fix properly, but I'm going to wait for a willing volunteer
      and/or more user pressure.
      d1eaeadb
  11. 22 Oct, 2017 1 commit
    • Tamar Christina's avatar
      Add stack traces on crashes on Windows · 99c61e22
      Tamar Christina authored
      Summary:
      This patch adds the ability to generate stack traces on crashes for Windows.
      When running in the interpreter this attempts to use symbol information from
      the interpreter and information we know about the loaded object files to
      resolve addresses to symbols.
      
      When running compiled it doesn't have this information and then defaults
      to using symbol information from PDB files. Which for now means only
      files compiled with ICC or MSVC will show traces compiled.
      
      But I have a future patch that may address this shortcoming.
      
      Also since I don't know how to walk a pure haskell stack, I can for now
      only show the last entry. I'm hoping to figure out how Apply.cmm works to
      be able to walk the stalk and give more entries for pure haskell code.
      
      In GHCi
      
      ```
      $ echo main | inplace/bin/ghc-stage2.exe --interactive ./testsuite/tests/rts/derefnull.hs
      GHCi, version 8.3.20170830: http://www.haskell.org/ghc/  :? for help
      Ok, 1 module loaded.
      Prelude Main>
      Access violation in generated code when reading 0x0
      
       Attempting to reconstruct a stack trace...
      
         Frame        Code address
       * 0x77cde10    0xc370229 E:\..\base\dist-install\build\HSbase-4.10.0.0.o+0x190031
                       (base_ForeignziStorable_zdfStorableInt4_info+0x3f)
      ```
      
      and compiled
      
      ```
      Access violation in generated code when reading 0x0
      
       Attempting to reconstruct a stack trace...
      
         Frame        Code address
       * 0xf0dbd0     0x40bb01 E:\..\rts\derefnull.run\derefnull.exe+0xbb01
      ```
      
      Test Plan: ./validate
      
      Reviewers: austin, hvr, bgamari, erikd, simonmar
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3913
      99c61e22
  12. 20 Oct, 2017 1 commit
    • Simon Peyton Jones's avatar
      Improve kick-out in the constraint solver · 3acd6164
      Simon Peyton Jones authored
      This patch was provoked by Trac #14363.  Turned out that we were
      kicking out too many constraints in TcSMonad.kickOutRewritable, and
      that mean that the work-list never became empty: infinite loop!
      
      That in turn made me look harder at the Main Theorem in
      Note [Extending the inert equalities].
      
      Main changes
      
      * Replace TcType.isTyVarExposed by TcType.isTyVarHead.  The
        over-agressive isTyVarExposed is what caused Trac #14363.
        See Note [K3: completeness of solving] in TcSMonad.
      
      * TcType.Make anyRewriteableTyVar role-aware.  In particular,
            a ~R ty
        cannot rewrite
            b ~R f a
        See Note [anyRewriteableTyVar must be role-aware].  That means
        it has to be given a role argument, which forces a little
        refactoring.
      
        I think this change is fixing a bug that hasn't yet been reported.
        The actual reported bug is handled by the previous bullet.  But
        this change is definitely the Right Thing
      
      The main changes are in TcSMonad.kick_out_rewritable, and in TcType
      (isTyVarExposed ---> isTyVarHead).
      
      I did a little unforced refactoring:
      
       * Use the cc_eq_rel field of a CTyEqCan when it is available, rather
         than recomputing it.
      
       * Define eqCanRewrite :: EqRel -> EqRel -> EqRel, and use it, instead
         of duplicating its logic
      3acd6164
  13. 19 Oct, 2017 5 commits
    • Jessica Clarke's avatar
      Untag the potential AP_STACK in stg_getApStackValzh · b6204f70
      Jessica Clarke authored
      If the AP_STACK has been evaluated and a GC has run, the BLACKHOLE
      indirection will have been removed, and the StablePtr for the original
      AP_STACK referred to be GHCi will therefore now point directly to the
      value, and may be tagged. Add a hist002 test for this, and make sure
      hist001 doesn't do an idle GC, so the case when it's still a BLACKHOLE
      is definitely also tested.
      
      Reviewers: austin, bgamari, erikd, simonmar
      
      Reviewed By: simonmar
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D4099
      b6204f70
    • Ryan Scott's avatar
      Fix #14369 by making injectivity warnings finer-grained · 8846a7fd
      Ryan Scott authored
      Summary:
      Previously, GHC would always raise the possibility that a
      type family might not be injective in certain error messages, even if
      that type family actually //was// injective. Fix this by actually
      checking for a type family's lack of injectivity before emitting
      such an error message.
      
      Test Plan: ./validate
      
      Reviewers: goldfire, austin, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, thomie
      
      GHC Trac Issues: #14369
      
      Differential Revision: https://phabricator.haskell.org/D4106
      8846a7fd
    • Ryan Scott's avatar
      Error when deriving instances in hs-boot files · 101a8c77
      Ryan Scott authored
      Summary:
      According to the GHC users' guide, one cannot derive
      instances for data types in `.hs-boot` files.
      However, GHC was not enforcing this in practice, which led to
      #14365.
      
      Fix this by actually throwing an error if a derived instance is
      detected in an `.hs-boot` file (and recommend how to fix it in the
      error message.)
      
      Test Plan: make test TEST=T14365
      
      Reviewers: ezyang, austin, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, thomie
      
      GHC Trac Issues: #14365
      
      Differential Revision: https://phabricator.haskell.org/D4102
      101a8c77
    • Ryan Scott's avatar
      Disable -XRebindableSyntax when running internal GHCi expressions · e023e78b
      Ryan Scott authored
      Summary:
      It's well known that `-XRebindableSyntax` doesn't play
      nicely with some of the internal expressions that GHCi runs. #13385
      was one example where this problem arose, which was fixed at the time
      by simply avoiding the use of `do`-notation in these internal GHCi
      expressions. That seemed to work, but it was a technique that proved
      not to scale, as #14342 demonstrated //another// example where
      `-XRebindableSyntax` can bite.
      
      Instead of delicately arranging the internal GHCi expressions to
      avoid anything that might be covered under `-XRebindableSyntax`,
      this patch takes the much more direct approach of disabling
      `-XRebindableSyntax` entirely when running any internal GHCi
      expression. This shouldn't hurt, since nothing internal to GHCi was
      taking advantage of the extension in the first place, and moreover,
      we can have greater confidence that some other obscure
      `-XRebindableSyntax` corner case won't pop up in the future. As an
      added bonus, this lets us once again use `do`-notation in the code
      that had to be changed when #13385 was (hackily) fixed before.
      
      Test Plan: make test TEST=T14342
      
      Reviewers: bgamari, austin
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #14342
      
      Differential Revision: https://phabricator.haskell.org/D4086
      e023e78b
    • Ryan Scott's avatar
      Accept test output for #14350 · 20ae22b0
      Ryan Scott authored
      20ae22b0
  14. 18 Oct, 2017 2 commits
    • Simon Peyton Jones's avatar
      Better solving for representational equalities · 5a66d574
      Simon Peyton Jones authored
      This patch adds a bit of extra solving power for representational
      equality constraints to fix Trac #14333
      
      The main changes:
      
      * Fix a buglet in TcType.isInsolubleOccursCheck which wrongly
        reported a definite occurs-check error for (a ~R# b a)
      
      * Get rid of TcSMonad.emitInsolubles.  It had an ad-hoc duplicate-removal
        piece that is better handled in interactIrred, now that insolubles
        are Irreds.
      
        We need a little care to keep inert_count (which does not include
        insolubles) accurate.
      
      * Refactor TcInteract.solveOneFromTheOther, to return a much simpler
        type.  It was just over-complicated before.
      
      * Make TcInteract.interactIrred look for constraints that match
        either way around, in TcInteract.findMatchingIrreds
      
      This wasn't hard and it cleaned up quite a bit of code.
      5a66d574
    • Simon Peyton Jones's avatar
      Don't deeply expand insolubles · 74cd1be0
      Simon Peyton Jones authored
      Trac #13450 went bananas if we expand insoluble constraints.
      Better just to leave them un-expanded.
      
      I'm not sure in detail about why it goes so badly wrong; but
      regardless, the less we mess around with insoluble contraints
      the better the error messages will be.
      74cd1be0
  15. 16 Oct, 2017 6 commits
    • Herbert Valerio Riedel's avatar
      Bump ghc-prim to 0.5.2.0 and update changelog · 6cb46421
      Herbert Valerio Riedel authored
      This is prompted by the addition of `compareByteArrays#` in
      e3ba26f8
      
      NOTE: We may switch to synchronise `ghc-prim` with GHC's version at some point
      6cb46421
    • Jessica Clarke's avatar
      RtClosureInspect: Fix inspecting Char# on 64-bit big-endian · d6c33da8
      Jessica Clarke authored
      Char# is represented with a full machine word, whereas Char's Storable
      instance uses an Int32, so we can't just treat it like a single-element
      Char array. Instead, read it as an Int and use chr to turn it into a
      Char. This fixes Trac #11262.
      
      Reviewers: austin, hvr, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #11262
      
      Differential Revision: https://phabricator.haskell.org/D4089
      d6c33da8
    • Edward Z. Yang's avatar
      Levity polymorphic Backpack. · fd8b044e
      Edward Z. Yang authored
      
      
      This patch makes it possible to specify non * kinds of
      abstract data types in signatures, so you can have
      levity polymorphism through Backpack, without the runtime
      representation constraint!
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: andrewthad, bgamari, austin, goldfire
      
      Reviewed By: bgamari
      
      Subscribers: goldfire, rwbarton, thomie
      
      GHC Trac Issues: #13955
      
      Differential Revision: https://phabricator.haskell.org/D3825
      fd8b044e
    • Herbert Valerio Riedel's avatar
      Enable testing 'Natural' type in TEST=arith011 · 843772b8
      Herbert Valerio Riedel authored
      This now passes thanks to 5984a698 (re #13203)
      843772b8
    • Herbert Valerio Riedel's avatar
      Implement new `compareByteArrays#` primop · e3ba26f8
      Herbert Valerio Riedel authored
      The new primop
      
          compareByteArrays# :: ByteArray# -> Int# {- offset -}
                             -> ByteArray# -> Int# {- offset -}
                             -> Int# {- length -}
                             -> Int#
      
      allows to compare the subrange of the first `ByteArray#` to
      the (same-length) subrange of the second `ByteArray#` and returns a
      value less than, equal to, or greater than zero if the range is found,
      respectively, to be byte-wise lexicographically less than, to match,
      or be greater than the second range.
      
      Under the hood, the new primop is implemented in terms of the standard
      ISO C `memcmp(3)` function. It is currently an out-of-line primop but
      work is underway to optimise this into an inline primop for a future
      follow-up Differential (see D4091).
      
      This primop has applications in packages like `text`, `text-short`,
      `bytestring`, `text-containers`, `primitive`, etc.  which currently
      have to incur the overhead of an ordinary FFI call to directly or
      indirectly invoke `memcmp(3)` as well has having to deal with some
      `unsafePerformIO`-variant.
      
      While at it, this also improves the documentation for the existing
      `copyByteArray#` primitive which has a non-trivial type-signature
      that significantly benefits from a more explicit description of its
      arguments.
      
      Reviewed By: bgamari
      
      Differential Revision: https://phabricator.haskell.org/D4090
      e3ba26f8
    • Herbert Valerio Riedel's avatar
      Fix panic for `ByteArray#` arguments in CApiFFI foreign imports · add85cc2
      Herbert Valerio Riedel authored
      Declarations such as
      
        foreign import capi  unsafe "string.h strlen"
            c_strlen_capi :: ByteArray# -> IO CSize
      
        foreign import capi  unsafe "string.h memset"
            c_memset_capi :: MutableByteArray# s -> CInt -> CSize -> IO ()
      
      would cause GHC to panic because the CApiFFI c-wrapper generator didn't
      know what C type to use for `(Mutable)ByteArray#` types (unlike the
      `ccall` codepath).
      
      This addresses #9274
      
      Reviewed By: bgamari
      
      Differential Revision: https://phabricator.haskell.org/D4092
      add85cc2
  16. 12 Oct, 2017 2 commits
    • Simon Peyton Jones's avatar
      Re-apply "Typeable: Allow App to match arrow types" · 3de788c4
      Simon Peyton Jones authored
      This re-applies
       commit cc6be3a2
        Author: Ben Gamari <bgamari.foss@gmail.com>
        Date:   Tue Sep 19 18:57:38 2017 -0400
      
          Typeable: Allow App to match arrow types
      
      which was reverted because of Trac #14270.  Now the latter is
      fixed we can re-apply it.
      
      The original ticket was Trac #14236
      3de788c4
    • Simon Peyton Jones's avatar
      Do not bind coercion variables in SpecConstr rules · fb050a33
      Simon Peyton Jones authored
      Trac #14270 showed that SpecConstr could cause nasty Lint failures
      if it generates a RULE that binds coercion varables.  See
      
       * Note [SpecConstr and casts], and
       * the test simplCore/should_compile/T14270.
      
      This doesn't feel like the final word to me, because somehow the
      specialisation "ought" to work.  So I left in a debug WARN to yell if
      the new check acutally fires.
      
      Meanwhile, it stops the erroneous specialisation.
      
      binding coercion
      fb050a33