1. 27 Nov, 2019 1 commit
    • Sebastian Graf's avatar
      Make warnings for TH splices opt-in · 5a08f7d4
      Sebastian Graf authored
      In #17270 we have the pattern-match checker emit incorrect warnings. The
      reason for that behavior is ultimately an inconsistency in whether we
      treat TH splices as written by the user (`FromSource :: Origin`) or as
      generated code (`Generated`). This was first reported in #14838.
      
      The current solution is to TH splices as `Generated` by default and only
      treat them as `FromSource` when the user requests so
      (-fenable-th-splice-warnings). There are multiple reasons for opt-in
      rather than opt-out:
      
        * It's not clear that the user that compiles a splice is the author of the code
          that produces the warning. Think of the situation where she just splices in
          code from a third-party library that produces incomplete pattern matches.
          In this scenario, the user isn't even able to fix that warning.
        * Gathering information for producing the warnings (pattern-match check
          warnings in particular) is costly. There's no point in doing so if the user
          is not interested in those warnings.
      
      Fixes #17270, but not #14838, because the proper solution needs a GHC
      proposal extending the TH AST syntax.
      5a08f7d4
  2. 13 Nov, 2019 1 commit
  3. 07 Nov, 2019 1 commit
    • Ryan Scott's avatar
      Clean up TH's treatment of unary tuples (or, #16881 part two) · 708c60aa
      Ryan Scott authored
      !1906 left some loose ends in regards to Template Haskell's treatment
      of unary tuples. This patch ends to tie up those loose ends:
      
      * In addition to having `TupleT 1` produce unary tuples, `TupE [exp]`
        and `TupP [pat]` also now produce unary tuples.
      * I have added various special cases in GHC's pretty-printers to
        ensure that explicit 1-tuples are printed using the `Unit` type.
        See `testsuite/tests/th/T17380`.
      * The GHC 8.10.1 release notes entry has been tidied up a little.
      
      Fixes #16881. Fixes #17371. Fixes #17380.
      708c60aa
  4. 01 Nov, 2019 1 commit
  5. 25 Oct, 2019 1 commit
  6. 24 Oct, 2019 1 commit
  7. 23 Oct, 2019 1 commit
    • Ryan Scott's avatar
      Reify oversaturated data family instances correctly (#17296) · a19c7d17
      Ryan Scott authored
      `TcSplice` was not properly handling oversaturated data family
      instances, such as the example in #17296, as it dropped arguments due
      to carelessly zipping data family instance arguments with
      `tyConTyVars`. For data families, the number of `tyConTyVars` can
      sometimes be less than the number of arguments it can accept in a
      data family instance due to the fact that data family instances can
      be oversaturated.
      
      To account for this, `TcSplice.mkIsPolyTvs` has now been renamed to
      `tyConArgsPolyKinded` and now factors in `tyConResKind` in addition
      to `tyConTyVars`. I've also added
      `Note [Reified instances and explicit kind signatures]` which
      explains the various subtleties in play here.
      
      Fixes #17296.
      a19c7d17
  8. 13 Oct, 2019 1 commit
  9. 08 Oct, 2019 1 commit
    • Richard Eisenberg's avatar
      Solve constraints from top-level groups sooner · 9612e91c
      Richard Eisenberg authored
      Previously, all constraints from all top-level groups (as
      separated by top-level splices) were lumped together and solved
      at the end. This could leak metavariables to TH, though, and
      that's bad. This patch solves each group's constraints before
      running the next group's splice.
      
      Naturally, we now report fewer errors in some cases.
      
      One nice benefit is that this also fixes #11680, but in a much
      simpler way than the original fix for that ticket. Admittedly,
      the error messages degrade just a bit from the fix from #11680
      (previously, we informed users about variables that will be
      brought into scope below a top-level splice, and now we just
      report an out-of-scope error), but the amount of complexity
      required throughout GHC to get that error was just not worth it.
      
      This patch thus reverts much of
      f93c9517.
      
      Fixes #16980
      
      Test cases: th/T16980{,a}
      9612e91c
  10. 28 Sep, 2019 1 commit
  11. 26 Jul, 2019 1 commit
  12. 05 Jul, 2019 1 commit
  13. 02 Jul, 2019 1 commit
  14. 12 Jun, 2019 1 commit
  15. 21 May, 2019 1 commit
    • Ryan Scott's avatar
      Fix #16666 by parenthesizing contexts in Convert · 4a6c8436
      Ryan Scott authored
      Most places where we convert contexts in `Convert` are actually in
      positions that are to the left of some `=>`, such as in superclasses
      and instance contexts. Accordingly, these contexts need to be
      parenthesized at `funPrec`. To accomplish this, this patch changes
      `cvtContext` to require a precedence argument for the purposes of
      calling `parenthesizeHsContext` and adjusts all `cvtContext` call
      sites accordingly.
      4a6c8436
  16. 14 May, 2019 1 commit
  17. 08 Mar, 2019 1 commit
    • Sylvain Henry's avatar
      TH: support raw bytes literals (#14741) · 224a6b86
      Sylvain Henry authored
      GHC represents String literals as ByteString internally for efficiency
      reasons. However, until now it wasn't possible to efficiently create
      large string literals with TH (e.g. to embed a file in a binary, cf #14741):
      TH code had to unpack the bytes into a [Word8] that GHC then had to re-pack
      into a ByteString.
      
      This patch adds the possibility to efficiently create a "string" literal
      from raw bytes. We get the following compile times for different sizes
      of TH created literals:
      
      || Size || Before || After  || Gain ||
      || 30K  || 2.307s || 2.299  || 0%   ||
      || 3M   || 3.073s || 2.400s || 21%  ||
      || 30M  || 8.517s || 3.390s || 60%  ||
      
      Ticket #14741 can be fixed if the original code uses this new TH feature.
      224a6b86
  18. 01 Mar, 2019 1 commit
    • Ryan Scott's avatar
      Visible dependent quantification · c26d299d
      Ryan Scott authored
      This implements GHC proposal 35
      (https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0035-forall-arrow.rst)
      by adding the ability to write kinds with
      visible dependent quantification (VDQ).
      
      Most of the work for supporting VDQ was actually done _before_ this
      patch. That is, GHC has been able to reason about kinds with VDQ for
      some time, but it lacked the ability to let programmers directly
      write these kinds in the source syntax. This patch is primarly about
      exposing this ability, by:
      
      * Changing `HsForAllTy` to add an additional field of type
        `ForallVisFlag` to distinguish between invisible `forall`s (i.e,
        with dots) and visible `forall`s (i.e., with arrows)
      * Changing `Parser.y` accordingly
      
      The rest of the patch mostly concerns adding validity checking to
      ensure that VDQ is never used in the type of a term (as permitting
      this would require full-spectrum dependent types). This is
      accomplished by:
      
      * Adding a `vdqAllowed` predicate to `TcValidity`.
      * Introducing `splitLHsSigmaTyInvis`, a variant of `splitLHsSigmaTy`
        that only splits invisible `forall`s. This function is used in
        certain places (e.g., in instance declarations) to ensure that GHC
        doesn't try to split visible `forall`s (e.g., if it tried splitting
        `instance forall a -> Show (Blah a)`, then GHC would mistakenly
        allow that declaration!)
      
      This also updates Template Haskell by introducing a new `ForallVisT`
      constructor to `Type`.
      
      Fixes #16326. Also fixes #15658 by documenting this feature in the
      users' guide.
      c26d299d
  19. 24 Feb, 2019 1 commit
  20. 12 Feb, 2019 1 commit
    • Ryan Scott's avatar
      Fix #16293 by cleaning up Proxy# infelicities · 012257c1
      Ryan Scott authored
      This bug fixes three problems related to `Proxy#`/`proxy#`:
      
      1. Reifying it with TH claims that the `Proxy#` type constructor has
         two arguments, but that ought to be one for consistency with
         TH's treatment for other primitive type constructors like `(->)`.
         This was fixed by just returning the number of
         `tyConVisibleTyVars` instead of using `tyConArity` (which includes
         invisible arguments).
      2. The role of `Proxy#`'s visible argument was hard-coded as nominal.
         Easily fixed by changing it to phantom.
      3. The visibility of `proxy#`'s kind argument was specified, which
         is different from the `Proxy` constructor (which treats it as
         inferred). Some minor refactoring in `proxyHashId` fixed ths up.
      
         Along the way, I had to introduce a `mkSpecForAllTy` function, so
         I did some related Haddock cleanup in `Type`, where that function
         lives.
      012257c1
  21. 10 Feb, 2019 1 commit
    • Matthew Pickering's avatar
      Capture and simplify constraints arising from running typed splices · a48753bd
      Matthew Pickering authored
      This fixes a regression caused by #15471 where splicing in a trivial
      program such as `[|| return () ||]` would fail as the dictionary for
      `return` would never get bound in the module containing the splice.
      
      Arguably this is symptomatic of a major problem affecting TTH where we
      serialise renamed asts and then retype check them. The reference to the
      dictionary should be fully determined at the quote site so that splicing
      doesn't have to solve any implicits at all. It's a coincidence this
      works due to coherence but see #15863 and #15865 for examples where
      things do go very wrong.
      
      Fixes #16195
      a48753bd
  22. 08 Feb, 2019 1 commit
  23. 30 Jan, 2019 3 commits
  24. 28 Jan, 2019 1 commit
    • Ryan Scott's avatar
      Use sigPrec in more places in Convert and HsUtils · b1e569a5
      Ryan Scott authored
      Trac #16183 was caused by TH conversion (in `Convert`) not properly
      inserting parentheses around occurrences of explicit signatures where
      appropriate, such as in applications, function types, and type family
      equations. Solution: use `parenthesizeHsType sigPrec` in these
      places. While I was in town, I also updated `nlHsFunTy` to do the
      same thing.
      b1e569a5
  25. 23 Jan, 2019 1 commit
  26. 21 Jan, 2019 1 commit
  27. 11 Jan, 2019 1 commit
  28. 06 Jan, 2019 1 commit
  29. 03 Jan, 2019 1 commit
    • My Nguyen's avatar
      Visible kind application · 17bd1635
      My Nguyen authored
      Summary:
      This patch implements visible kind application (GHC Proposal 15/#12045), as well as #15360 and #15362.
      It also refactors unnamed wildcard handling, and requires that type equations in type families in Template Haskell be
      written with full type on lhs. PartialTypeSignatures are on and warnings are off automatically with visible kind
      application, just like in term-level.
      
      There are a few remaining issues with this patch, as documented in
      ticket #16082.
      
      Includes a submodule update for Haddock.
      
      Test Plan: Tests T12045a/b/c/TH1/TH2, T15362, T15592a
      
      Reviewers: simonpj, goldfire, bgamari, alanz, RyanGlScott, Iceland_jack
      
      Subscribers: ningning, Iceland_jack, RyanGlScott, int-index, rwbarton, mpickering, carter
      
      GHC Trac Issues: `#12045`, `#15362`, `#15592`, `#15788`, `#15793`, `#15795`, `#15797`, `#15799`, `#15801`, `#15807`, `#15816`
      
      Differential Revision: https://phabricator.haskell.org/D5229
      17bd1635
  30. 29 Dec, 2018 1 commit
  31. 24 Dec, 2018 1 commit
  32. 22 Dec, 2018 1 commit
  33. 11 Dec, 2018 1 commit
  34. 03 Dec, 2018 1 commit
    • Ryan Scott's avatar
      Fix embarrassing infinite loop in pprParendType · 89d80921
      Ryan Scott authored
      Summary:
      `pprParendType` was missing an explicit case for
      `EqualityT`, which caused it to fall through to a catch-all case
      that invokes `ppr`. But `ppr` itself does not have a case for a
      partial application of `EqualityT`, so //it// falls back to
      `pprParendType`, resulting in an infinite loop!
      
      The fix is simple: add a case for `EqualityT` in `pprParendType`.
      While I was in the neighborhood, I removed the catch-call case in
      `pprParendType` to make this sort of mistake less likely to happen
      in the future.
      
      Test Plan: make test TEST=T15985
      
      Reviewers: bgamari, monoidal, simonpj
      
      Reviewed By: monoidal, simonpj
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15985
      
      Differential Revision: https://phabricator.haskell.org/D5403
      89d80921
  35. 22 Nov, 2018 1 commit
  36. 08 Nov, 2018 1 commit
    • Ryan Scott's avatar
      Fix #15845 by defining etaExpandFamInstLHS and using it · 63a81707
      Ryan Scott authored
      Summary:
      Both #9692 and #14179 were caused by GHC being careless
      about using eta-reduced data family instance axioms. Each of those
      tickets were fixed by manually whipping up some code to eta-expand
      the axioms. The same sort of issue has now caused #15845, so I
      figured it was high time to factor out the code that each of these
      fixes have in common.
      
      This patch introduces the `etaExpandFamInstLHS` function, which takes
      a family instance's type variables, LHS types, and RHS type, and
      returns type variables and LHS types that have been eta-expanded if
      necessary, in the case of a data family instance. (If it's a type
      family instance, `etaExpandFamInstLHS` just returns the supplied type
      variables and LHS types unchanged).
      
      Along the way, I noticed that many references to
      `Note [Eta reduction for data families]` (in `FamInstEnv`) had
      slightly bitrotted (they either referred to a somewhat different
      name, or claimed that the Note lived in a different module), so
      I took the liberty of cleaning those up.
      
      Test Plan: make test TEST="T9692 T15845"
      
      Reviewers: goldfire, bgamari
      
      Reviewed By: goldfire
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15845
      
      Differential Revision: https://phabricator.haskell.org/D5294
      63a81707
  37. 29 Oct, 2018 1 commit
    • Ryan Scott's avatar
      Fix #15815 by parenthesizing the arguments to infix ~ · b8a797ec
      Ryan Scott authored
      An unfortunate consequence of commit
      b9483981 (`Remove HsEqTy and XEqTy`)
      is infix uses of `~` in TH quotes now desugar differently than
      before. In particular, we have that:
      
      ```haskell
      a ~ (Int -> Int)
      ```
      
      Now desugars to:
      
      ```haskell
      HsOpTy a (~) (HsOpTy Int (->) Int)
      ```
      
      Which GHC interprets as being:
      
      ```haskell
      a ~ Int -> Int
      ```
      
      Or, equivalently:
      
      ```haskell
      (a ~ Int) -> Int
      ```
      
      Which is different than what was intended! This is the cause
      of #15815.
      
      All of this has revealed that we likely need to renovate the way we
      desugar infix type operators to be more consistent with the treatment
      for infix expressions (see
      https://ghc.haskell.org/trac/ghc/ticket/15815#comment:5 for more on
      this.) Doing so would constitute a breaking change, however, so we
      will likely want to wait until another major GHC release to do this.
      
      In the meantime, this patch offers a non-invasive change to the way
      that infix uses of `~` are desugared. This makes the program
      in #15815 compile again by inserting extra `HsParTy`s around the
      arguments to `~` if they are lacking them.
      
      Test Plan: make test TEST=T15815
      
      Reviewers: int-index, goldfire, bgamari
      
      Reviewed By: int-index
      
      Subscribers: int-e, rwbarton, carter
      
      GHC Trac Issues: #15815
      
      Differential Revision: https://phabricator.haskell.org/D5274
      b8a797ec
  38. 27 Oct, 2018 1 commit
    • mayac's avatar
      More explicit foralls (GHC Proposal 0007) · 512eeb9b
      mayac authored
      Allow the user to explicitly bind type/kind variables in type and data
      family instances (including associated instances), closed type family
      equations, and RULES pragmas. Follows the specification of GHC
      Proposal 0007, also fixes #2600. Advised by Richard Eisenberg.
      
      This modifies the Template Haskell AST -- old code may break!
      
      Other Changes:
      - convert HsRule to a record
      - make rnHsSigWcType more general
      - add repMaybe to DsMeta
      
      Includes submodule update for Haddock.
      
      Test Plan: validate
      
      Reviewers: goldfire, bgamari, alanz
      
      Subscribers: simonpj, RyanGlScott, goldfire, rwbarton,
                   thomie, mpickering, carter
      
      GHC Trac Issues: #2600, #14268
      
      Differential Revision: https://phabricator.haskell.org/D4894
      512eeb9b