1. 29 Aug, 2017 8 commits
    • Simon Peyton Jones's avatar
      Use a well-kinded substitution to instantiate · 4455c86d
      Simon Peyton Jones authored
      In tcDataConPat we were creating an ill-kinded substitution
      -- or at least one that is well kinded only after you have solved
      other equalities.  THat led to a crash, because the instantiated
      data con type was ill-kinded.
      
      This patch guarantees that the instantiating substitution is
      well-kinded.
      
      Fixed Trac #14154
      4455c86d
    • Simon Peyton Jones's avatar
      Small refactoring of meta-tyvar cloning · 86e6a5f2
      Simon Peyton Jones authored
      No change in behaviour.
      86e6a5f2
    • Simon Peyton Jones's avatar
      Refactor bindHsQTyVars and friends · 0257dacf
      Simon Peyton Jones authored
      This work was triggered by Trac #13738, which revealed to me that
      the code RnTypes.bindHsQTyVars and bindLHsTyVarBndrs was a huge
      tangled mess -- and outright wrong on occasion as the ticket showed.
      
      The big problem was that bindLHsTyVarBndrs (which is invoked at every
      HsForAll, including nested higher rank ones) was attempting to bind
      implicit kind variables, which it has absolutely no busineess doing.
      Imlicit kind quantification is done at the outside only, in fact
      precisely where we have HsImplicitBndrs or LHsQTyVars (which also
      has implicit binders).
      
      Achieving this move was surprisingly hard, because more and more
      barnacles had accreted aroud the original mistake.  It's much
      much better now.
      
      Summary of changes.  Almost all the action is in RnTypes.
      
      * Implicit kind variables are bound only by
        - By bindHsQTyVars, which deals with LHsQTyVars
        - By rnImplicitBndrs, which deals with HsImplicitBndrs
      
      * bindLHsTyVarBndrs, and bindLHsTyVarBndr are radically simplified.
        They simply does far less, and have lots their forest of
        incomprehensible accumulating parameters.  (To be fair, some of
        the code in bindLHsTyVarBndrs just moved to bindHsQTyVars, but
        in much more perspicuous form.)
      
      * The code that checks if a variable appears in both a kind and
        a type (triggering RnTypes.mixedVarsErr) was bizarre.  E.g.
        we had this in RnTypes.extract_hs_tv_bndrs
             ; check_for_mixed_vars bndr_kvs acc_tvs
             ; check_for_mixed_vars bndr_kvs body_tvs
             ; check_for_mixed_vars body_tvs acc_kvs
             ; check_for_mixed_vars body_kvs acc_tvs
             ; check_for_mixed_vars locals body_kvs
        I cleaned all this up; now we check for mixed use at binding
        sites only.
      
      * Checks for "Variable used as a kind before being bound", like
           data T (a :: k) k = rhs
        now just show up straightforwardly as "k is not in scope".
        See Note [Kind variable ordering]
      
      * There are some knock-on simplifications in RnSource.
      0257dacf
    • Simon Peyton Jones's avatar
      Add TcRnMonad.unlessXOptM · 6f050d9c
      Simon Peyton Jones authored
      This usefully joins whenXOptM; there are probably lots of places
      we should use it!
      
      This patch does not use new new function at all; but it's preparing
      for an upcoming patch when I do use it.
      6f050d9c
    • Simon Peyton Jones's avatar
      A bit more -ddump-tc tracing · 547e4c03
      Simon Peyton Jones authored
      547e4c03
    • Simon Peyton Jones's avatar
      Better debug-printing for Outputable TyConBinder · 8834d482
      Simon Peyton Jones authored
      Anon and Required were printed the same :-(.  This is only for
      debug printing, so I switched to a slightly more verbose and
      explicit format
      8834d482
    • Simon Peyton Jones's avatar
      Comments only · 6e0e0b0e
      Simon Peyton Jones authored
      Better comment on con_qvars in ConDecl
      6e0e0b0e
    • David Feuer's avatar
      Make parsed AST dump output lazily · 29da01e0
      David Feuer authored
      Previously, `showAstData` produced a `String`. That `String` would
      then be converted to a `Doc` using `text` to implement
      `-ddump-parsed-ast`. But rendering `text` calculates the length
      of the `String` before doing anything else. Since the AST can be
      very large, this was bad: the whole dump string (potentially hundreds
      of millions of `Char`s) was accumulated in memory.
      
      Now, `showAstData` produces a `Doc` directly, which seems to work
      a lot better. As an extra bonus, the code is simpler and cleaner.
      The formatting has changed a bit, as the previous ad hoc approach
      didn't really match the pretty printer too well. If someone cares
      enough to request adjustments, we can surely make them.
      
      Reviewers: austin, bgamari, mpickering, alanz
      
      Reviewed By: bgamari
      
      Subscribers: mpickering, rwbarton, thomie
      
      GHC Trac Issues: #14161
      
      Differential Revision: https://phabricator.haskell.org/D3894
      29da01e0
  2. 28 Aug, 2017 2 commits
  3. 26 Aug, 2017 1 commit
  4. 25 Aug, 2017 11 commits
    • Ben Gamari's avatar
      Rip out mkUserGuidePart · 8f19c65c
      Ben Gamari authored
      Reviewers: austin, hvr
      
      Subscribers: rwbarton, thomie, erikd
      
      Differential Revision: https://phabricator.haskell.org/D3886
      8f19c65c
    • Ben Gamari's avatar
      rts: Fix ASSERTs with space before opening paren · 76e59a27
      Ben Gamari authored
      Reviewers: austin, erikd, simonmar
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3885
      76e59a27
    • Ben Gamari's avatar
      rts: Fix references to Note [BFD import library] · 80ccea85
      Ben Gamari authored
      Reviewers: austin, erikd, simonmar
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3884
      80ccea85
    • Ben Gamari's avatar
      rts: Fix warnings on aarch64 and clean up style · f135fb2a
      Ben Gamari authored
      Reviewers: austin, erikd, simonmar
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3877
      f135fb2a
    • Ben Gamari's avatar
      Add strict variant of iterate · a67b66e6
      Ben Gamari authored
      Summary: This closes the nearly-eight-year-old #3474.
      
      Test Plan: Validate
      
      Reviewers: RyanGlScott, austin, hvr
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #3474
      
      Differential Revision: https://phabricator.haskell.org/D3870
      a67b66e6
    • Simon Peyton Jones's avatar
    • Simon Peyton Jones's avatar
      Don't do the RhsCtxt thing for join points · 8649535c
      Simon Peyton Jones authored
      This minor change fixes Trac #14137.
      
      It is described in Note [Join point RHSs] in OccurAnal
      8649535c
    • Simon Peyton Jones's avatar
      Refactor the Mighty Simplifier · 33452dfc
      Simon Peyton Jones authored
      Triggered by #12150, and the knock-on effects of join points, I did a
      major refactoring of the Simplifier.  This is a big patch that change
      a lot of Simplify.hs: I did a lot of other re-organisation.
      
      The main event
      ~~~~~~~~~~~~~~
      Since the dawn of time we have had
        simplExpr :: SimplEnv -> InExpr -> SimplCont
                  -> SimplM (SimplEnv, OutExpr)
      
      What's that SimplEnv in the result?  When simplifying an expression the
      simplifier add floated let-bindings to the SimplEnv, extending the
      in-scope set appropriately, and hence needs to resturn the SimplEnv at
      the end.  The mode, flags, substitution in the returned SimplEnv were
      all irrelevant: it was just the floating bindings.
      
      It's strange to accumulate part of the /result/ in the /environment/
      argument!  And indeed its leads to all manner of mysterious calls to
      zapFloats and transferring of floats from one SimplEnv to another.
      It got worse with join points, so I finally bit the bullet and refactored.
      Now we have
        simplExpr :: SimplEnv -> InExpr -> SimplCont
                  -> SimplM (SimplFloats, OutExpr)
        -- See Note [The big picture]
      and the SimplEnv no longer has floats in it.  The code is no shorter,
      but it /is/ easier to understand.
      
      Main changes
      
      * Remove seLetFloats field from SimplEnv
      
      * Define new data type SimplFloats, and functions over it
      
      * Change the types of simplExpr, simplBind, and their many variants,
        to follow the above plan
      
      Bottoming bindings
      ~~~~~~~~~~~~~~~~~~
      I made one other significant change in SimplUtils (not just refactoring),
      related to Trac #12150 comment:16.  Given
        x = <rhs>
      where <rhs> turns out to be a bottoming expression, propagate that
      information to x's IdInfo immediately.  That's always good, because
      it makes x be inlined less (we don't inline bottoming things), and
      it allows (case x of ...) to drop the dead alterantives immediately.
      Moreover, we are doing the analysis anyway, in tryEtaExpandRhs, which
      calls CoreArity.findRhsArity, which already does simple bottom analysis.
      So we are generating the information; all we need do is to atach the
      bottoming info to the IdInfo.
      
      See Note [Bottoming bindings]
      
      Smaller refactoring
      ~~~~~~~~~~~~~~~~~~~
      * Rename SimplifierMode to SimplMode
      * Put DynFlags as a new field in SimplMode, to make fewer
        monadic calls to getDynFlags.
      * Move the code in addPolyBind into abstractFloats
      * Move the "don't eta-expand join points" into tryEtaExpandRhs
      33452dfc
    • Simon Peyton Jones's avatar
      Bottoming expressions should not be expandable · 407c11b8
      Simon Peyton Jones authored
      This patch changes isExpandableApp and isWorkFreeApp to respond
      False to bottoming applications.  I found that if we had
      
        x = undefined <dict-expr>
      
      then prepareRhs was ANF'ing it to
      
        d = <dict-expr>
        x = undefined d
      
      which is stupid (no gain); and worse it made the simplifier iterate
      indefinitely.  It showed up when I started marking 'x' as a bottoming
      Id more aggresssively than before; but it's been a lurking bug for
      ages.
      
      It was convenient to make isWorkFreeApp also return False for
      bottoming applications, and I see no reason not to do so.
      
      That leaves isCheapApp.  It currently replies True to bottoming
      applications, but I don't see why that's good..  Something to try
      later.
      407c11b8
    • Simon Peyton Jones's avatar
      Restrict exprOkForSpeculation/case to unlifted types · a0b7b100
      Simon Peyton Jones authored
      Consider
        case x of y
          DEFAULT -> let v::Int# = case y of
                                     True  -> e1
                                     False -> e2
                      in ...
      
      Previously this would have been ok-for-speculation because
      y is evaluated.  But the binder-swap done
      by SetLevels would transform the inner alternative to
           DEFAULT -> let v::Int# = case x of { ... }
                      in ...)
      which does /not/ satisfy the let/app invariant, because x is
      not evaluated.
      
      I don't know why this has never bitten us before, but it began
      to bite when I did upcoming refactoring of the Simplifier.
      
      So this patch narrows exprOkForSpeculation to only work for
      /unlifted/ cases.
      
      To make this work I had to make exprOkForSpeculation non-polymorphic
      in the binder type, which has a little knock-on for is use in
      SetLevels.
      
      (It's annoying that we need to handle cases at all, but see
       Note [exprOkForSpeculation: case expressions])
      a0b7b100
    • Ben Gamari's avatar
      CNF: Implement compaction for small pointer arrays · 5f3d2d3b
      Ben Gamari authored
      Test Plan: Validate
      
      Reviewers: austin, erikd, simonmar, dfeuer
      
      Reviewed By: dfeuer
      
      Subscribers: rwbarton, andrewthad, thomie, dfeuer
      
      GHC Trac Issues: #13860, #13857
      
      Differential Revision: https://phabricator.haskell.org/D3888
      5f3d2d3b
  5. 24 Aug, 2017 4 commits
  6. 22 Aug, 2017 14 commits
    • Ben Gamari's avatar
    • Ben Gamari's avatar
      Add support for producing position-independent executables · 3625728a
      Ben Gamari authored
      Previously due to #12759 we disabled PIE support entirely. However, this
      breaks the user's ability to produce PIEs. Add an explicit flag, -fPIE,
      allowing the user to build PIEs.
      
      Test Plan: Validate
      
      Reviewers: rwbarton, austin, simonmar
      
      Subscribers: trommler, simonmar, trofi, jrtc27, thomie
      
      GHC Trac Issues: #12759, #13702
      
      Differential Revision: https://phabricator.haskell.org/D3589
      3625728a
    • Ben Gamari's avatar
      DynFlags: Add inverse of -dno-debug-output · dbaa9a23
      Ben Gamari authored
      Reviewers: austin
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #14142
      
      Differential Revision: https://phabricator.haskell.org/D3876
      dbaa9a23
    • Benjamin Hodgson's avatar
      Fixed a typo in template-haskell documentation · 028645ce
      Benjamin Hodgson authored
      The documentation for `Type`'s `ForallT` constructor had a typo (pun not
      intended). `ctxt` is separated from `type` in the surface syntax by a fat
      arrow (`=>`), not a thin arrow (`->`).
      028645ce
    • Chris Martin's avatar
      fix typo (expreesions -> expressions) · 090d8960
      Chris Martin authored
      090d8960
    • Ben Gamari's avatar
      Bump haddock submodule · 20c7053d
      Ben Gamari authored
      20c7053d
    • AlainODea's avatar
      Make law for Foldable.length explicit · cd5a9709
      AlainODea authored
      Test Plan: Documentation only. Not necessary.
      
      Reviewers: austin, hvr, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3878
      cd5a9709
    • Ben Gamari's avatar
      StgLint: Allow join point bindings of unlifted type · 9afaebef
      Ben Gamari authored
      As described in `Note [CoreSyn let/app invariant]` this is allowed.
      
      Fixes #14117.
      
      Test Plan: Build GHC with BuildFlavour=devel2 with -dstg-lint
      
      Reviewers: austin, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #14117
      
      Differential Revision: https://phabricator.haskell.org/D3857
      9afaebef
    • Edward Z. Yang's avatar
      Fix incorrect retypecheck loop in -j (#14075) · 4717ce86
      Edward Z. Yang authored
      
      
      The parallel codepath was incorrectly retypechecking the
      hs-boot ModIface prior to typechecking the hs file,
      which was inconsistent with the non-parallel case.  The
      non-parallel case gets it right: you don't want to retypecheck
      the hs-boot file itself (forwarding its declarations to hs)
      because you need it to be consistently knot-tied with itself
      when you compare the interfaces.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: bgamari, simonpj, austin
      
      Reviewed By: bgamari
      
      Subscribers: duog, rwbarton, thomie
      
      GHC Trac Issues: #14075
      
      Differential Revision: https://phabricator.haskell.org/D3815
      4717ce86
    • Douglas Wilson's avatar
      Move validate cleaning from distclean to clean · afc2f798
      Douglas Wilson authored
      This bit me today: I was in validate mode without realising it and "make
      clean" didn't help. I don't see a reason for this to be in distclean, as
      it isn't generated by ./configure, which is the rule described in
      https://ghc.haskell.org/trac/ghc/wiki/Building/Using
      
      Test Plan: Is there a reason for this to be in distclean?
      
      Reviewers: austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3814
      afc2f798
    • Ryan Scott's avatar
      Make the Read instance for Proxy (and friends) ignore precedence · 8fd95999
      Ryan Scott authored
      Summary:
      The `Read` instance for `Proxy`, as well as a handful of other data
      types in `base` which only have a single constructor, are doing something
      skeevy: they're requiring that they be surrounded by parentheses if the parsing
      precedence is sufficiently high. This means that `"Thing (Proxy)"` would parse,
      but not `"Thing Proxy"`. But the latter really ought to parse, since there's no
      need to surround a single constructor with parentheses. Indeed, that's the
      output of `show (Thing Proxy)`, so the current `Read` instance for `Proxy`
      violates `read . show = id`.
      
      The simple solution is to change `readParen (d > 10)` to `readParen False` in
      the `Read` instance for `Proxy`. But given that a derived `Read` instance would
      essentially accomplish the same thing, but with even fewer characters, I've
      opted to just replace the hand-rolled `Read` instance with a derived one.
      
      Test Plan: make test TEST=T12874
      
      Reviewers: ekmett, austin, hvr, goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #12874
      
      Differential Revision: https://phabricator.haskell.org/D3871
      8fd95999
    • Ryan Scott's avatar
      Revise function arity mismatch errors involving TypeApplications · 84760976
      Ryan Scott authored
      Summary:
      Currently, whenever you apply a function to too many arguments and
      some of those arguments happen to be visible type applications, the error
      message that GHC gives is rather confusing. Consider the message you receive
      when typechecking `id @Int 1 2`:
      
      ```
      The function `id` is applied to three arguments,
      but its type `Int -> Int` has only one
      ```
      
      This is baffling, since the two lines treat the visible type argument `@Int`
      differently. The top line ("applied to three arguments") includes `@Int`,
      whereas the bottom line ("has only one") excludes `@Int` from consideration.
      
      There are multiple ways one could fix this, which I explain in an addendum to
      `Note [Herald for matchExpectedFunTys]`. The approach adopted here is to change
      the herald of this error message to include visible type arguments, and to
      avoid counting them in the "applied to n arguments" part of the error. The end
      result is that the new error message for `id @Int 1 2` is now:
      
      ```
      The expression `id @Int` is applied to two arguments,
      but its type `Int -> Int` has only one
      ```
      
      Test Plan: make test TEST=T13902
      
      Reviewers: goldfire, austin, bgamari
      
      Reviewed By: goldfire
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #13902
      
      Differential Revision: https://phabricator.haskell.org/D3868
      84760976
    • Ryan Scott's avatar
      Fix #13885 by freshening reified GADT constructors' universal tyvars · 79b259ae
      Ryan Scott authored
      Summary:
      When reifying GADTs with Template Haskell, the universally quantified
      type variables were being reused across both the data type head and the
      constructors' type signatures. This had the annoying effect of causing sets
      of differently scoped variables to have the same uniques. To avoid this, we
      now freshen the universal tyvars before reifying the constructors so as to
      ensure they have distinct uniques.
      
      Test Plan: make test TEST=T13885
      
      Reviewers: goldfire, austin, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: rwbarton, thomie
      
      GHC Trac Issues: #13885
      
      Differential Revision: https://phabricator.haskell.org/D3867
      79b259ae
    • Ryan Scott's avatar
      Fix #14114 by checking for duplicate vars on pattern synonym RHSes · a89bb806
      Ryan Scott authored
      Summary:
      Because we weren't checking for duplicate variables on the right-hand
      sides of pattern synonyms, bogus definitions like this one passed the renamer:
      
      ```lang=haskell
      pattern Foo a <- (a,a)
      ```
      
      Luckily, the fix is simple.
      
      Test Plan: make test TEST=T14114
      
      Reviewers: mpickering, austin, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, thomie
      
      GHC Trac Issues: #14114
      
      Differential Revision: https://phabricator.haskell.org/D3866
      a89bb806