1. 29 Oct, 2018 1 commit
    • Ryan Scott's avatar
      Bump template-haskell version to 2.15.0.0 · e8a652f6
      Ryan Scott authored
      Summary:
      Commit 512eeb9b
      (`More explicit foralls (GHC Proposal 0007)`) introduced breaking
      changes to the Template Haskell AST. As a consequence of this, there
      are libraries in the wild that now fail to build on GHC HEAD (for
      instance, `th-abstraction`).
      
      This properly bumps the `template-haskell` library's version number
      to `2.15.0.0` so that these libraries can guard against these changes
      using `MIN_VERSION_template_haskell`.
      
      Test Plan: ./validate
      
      Reviewers: bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15818
      
      Differential Revision: https://phabricator.haskell.org/D5272
      e8a652f6
  2. 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
  3. 24 Oct, 2018 3 commits
    • Simon Peyton Jones's avatar
      Improve output from -ddump-types · 321bc1a6
      Simon Peyton Jones authored
      This patch makes a number of improvements to the output
      generated by -ddump-types
      
      * Prints data constructor separately
      * Omits empty chunks of output
      
      I was driven initially by the unhelpful existing output for
      data constructors, but ended up doing some refactoring.
      
      Lots of error message wibbles, but nothing significant.
      Certainly no change in user behaviour.
      
      (NB: It is just possible that I have failed to cleanly
           separate this patch from the next one, about
           isPredTy and friends.)
      321bc1a6
    • Ryan Scott's avatar
      Fix #15792 by not reifying invisible arguments in AppTys · bfd93f90
      Ryan Scott authored
      Summary:
      The `reifyType` function in `TcSplice` is carefully designed
      to avoid reifying visible arguments to `TyConApp`s. However, the same
      care was not given towards the `AppTy` case, which lead to #15792.
      
      This patch changes to the `AppTy` case of `reifyType` so that it
      consults the kind of the function type to determine which of the
      argument types are invisible (and therefore should be dropped) during
      reification. This required crafting a variant of `tyConArgFlags`,
      which I dubbed `appTyArgFlags`, that accept an arbitrary function
      `Type` instead of a `TyCon`.
      
      Test Plan: make test TEST=T15792
      
      Reviewers: goldfire, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, carter
      
      GHC Trac Issues: #15792
      
      Differential Revision: https://phabricator.haskell.org/D5252
      bfd93f90
    • Ryan Scott's avatar
      Keep top-level names in typed TH quotes alive · bb835c96
      Ryan Scott authored
      Summary:
      When renaming untyped TH quotes, some care is taken to
      ensure that uses of top-level names in quotes do not have their
      bindings discarded during desugaring. The same care was not applied
      to typed TH quotes, so this patch brings the two into sync.
      
      Test Plan: make test TEST=T15783
      
      Reviewers: bgamari, mpickering
      
      Reviewed By: mpickering
      
      Subscribers: mpickering, rwbarton, carter
      
      GHC Trac Issues: #15783
      
      Differential Revision: https://phabricator.haskell.org/D5248
      bb835c96
  4. 15 Oct, 2018 2 commits
    • Vladislav Zavialov's avatar
      Enable -Wcompat=error in the testsuite · 165d3d5d
      Vladislav Zavialov authored
      Enabling -Werror=compat in the testsuite allows us to easily see the
      impact that a new warning has on code. It also means that in the period
      between adding the warning and making the actual breaking change, all
      new test cases that are being added to the testsuite will be
      forwards-compatible. This is good because it will make the actual
      breaking change contain less irrelevant testsuite updates.
      
      Things that -Wcompat warns about are things that are going to break in
      the future, so we can be proactive and keep our testsuite
      forwards-compatible.
      
      This patch consists of two main changes:
      
      * Add `TEST_HC_OPTS += -Werror=compat` to the testsuite configuration.
      * Fix all broken test cases.
      
      Test Plan: Validate
      
      Reviewers: hvr, goldfire, bgamari, simonpj, RyanGlScott
      
      Reviewed By: goldfire, RyanGlScott
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15278
      
      Differential Revision: https://phabricator.haskell.org/D5200
      165d3d5d
    • Ryan Scott's avatar
      Fix #15738 by defining (and using) parenthesizeHsContext · 02b2116e
      Ryan Scott authored
      With `QuantifiedConstraints`, `forall`s can appear in more
      nested positions than they could before, but `Convert` and the TH
      pretty-printer were failing to take this into account. On the
      `Convert` side, this is fixed by using a `parenthesizeHsContext`
      to parenthesize singleton quantified constraints that appear to the
      left of a `=>`. (A similar fix is applied to the TH pretty-printer.)
      
      Test Plan: make test TEST=T15738
      
      Reviewers: goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15738
      
      Differential Revision: https://phabricator.haskell.org/D5222
      02b2116e
  5. 04 Oct, 2018 3 commits
    • Alec Theriault's avatar
      Set `infixr -1 ->` · 251e3424
      Alec Theriault authored
      Summary:
      This simply makes explicit what is already the case. Due to special
      treatment in the parser, `->` has the lowest fixity. This patch propagates
      that information to:
      
        * GHCi, where `:info ->` now return the right fixity
        * TH, where `reifyFixity` returns the right fixity
        * the generated sources for `GHC.Prim`
      
      See #15235.
      
      Test Plan: make test
      
      Reviewers: bgamari, alanz, RyanGlScott
      
      Reviewed By: RyanGlScott
      
      Subscribers: int-index, RyanGlScott, rwbarton, mpickering, carter
      
      GHC Trac Issues: #15235
      
      Differential Revision: https://phabricator.haskell.org/D5199
      251e3424
    • Alec Theriault's avatar
      Don't drop arguments in TH type arguments · ba163c3b
      Alec Theriault authored
      Summary:
      When converting from TH AST back to HsType, we were occasionally
      dropping type arguments. This resulted in incorrectly accepted programs
      as well as incorrectly rejected programs.
      
      Test Plan: make TEST=T15360a && make TEST=T15360b
      
      Reviewers: goldfire, bgamari, tdammers
      
      Reviewed By: bgamari, tdammers
      
      Subscribers: RyanGlScott, rwbarton, carter
      
      GHC Trac Issues: #15360
      
      Differential Revision: https://phabricator.haskell.org/D5188
      ba163c3b
    • Simon Peyton Jones's avatar
      Better -ddump-types · e9e66402
      Simon Peyton Jones authored
      The debug flag -ddump-types is supposed to show the type
      of Ids, and the kinds of type constructors.  It was doing
      the former but not the latter -- instead it was using
      showTyTying, which is actually less helpful when debugging.
      
      This patch changes it to print the kind and roles of the thing.
      
      I also made -ddump-types show pattern synonyms
      e9e66402
  6. 27 Sep, 2018 1 commit
    • Simon Marlow's avatar
      Fix for recover with -fexternal-interpreter (#15418) · d00c3086
      Simon Marlow authored
      Summary:
      When using -fexternal-interpreter, recover was not treating a Q
      compuation that simply registered an error with addErrTc as failing.
      
      Test Plan:
      New unit tests:
      * T15418 is the repro from in the ticket
      * TH_recover_warns is a new test to ensure that we're keeping warnings when
        the body of recover succeeds.
      
      Reviewers: bgamari, RyanGlScott, angerman, goldfire, erikd
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15418
      
      Differential Revision: https://phabricator.haskell.org/D5185
      d00c3086
  7. 14 Sep, 2018 2 commits
    • Krzysztof Gogolewski's avatar
      Fix T15502 on 32-bit · ecbe26b6
      Krzysztof Gogolewski authored
      Summary:
      The expected output uses a hardcoded value for
      maxBound :: Int.
      
      This should fix one of circleci failures on i386.
      
      Test Plan: make test TEST=T15502
      
      Reviewers: RyanGlScott, bgamari
      
      Reviewed By: RyanGlScott
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15502
      
      Differential Revision: https://phabricator.haskell.org/D5151
      ecbe26b6
    • Michael Sloan's avatar
      Add support for ImplicitParams and RecursiveDo in TH · 9c6b7493
      Michael Sloan authored
      Summary:
      This adds TH support for the ImplicitParams and RecursiveDo extensions.
      
      I'm submitting this as one review because I cannot cleanly make
      the two commits independent.
      
      Initially, my goal was just to add ImplicitParams support, and
      I found that reasonably straightforward, so figured I might
      as well use my newfound knowledge to address some other TH omissions.
      
      Test Plan: Validate
      
      Reviewers: goldfire, austin, bgamari, RyanGlScott
      
      Reviewed By: RyanGlScott
      
      Subscribers: carter, RyanGlScott, thomie
      
      GHC Trac Issues: #1262
      
      Differential Revision: https://phabricator.haskell.org/D1979
      9c6b7493
  8. 28 Aug, 2018 1 commit
    • Ryan Scott's avatar
      Fix #15572 by checking for promoted names in ConT · c46a5f20
      Ryan Scott authored
      Summary:
      When converting `ConT`s to `HsTyVar`s in `Convert`, we were
      failing to account for the possibility of promoted data constructor
      names appearing in a `ConT`, which could result in improper
      pretty-printing results (as observed in #15572). The fix is
      straightforward: use `Promoted` instead of `NotPromoted` when the
      name of a `ConT` is a data constructor name.
      
      Test Plan: make test TEST=T15572
      
      Reviewers: goldfire, bgamari, simonpj, monoidal
      
      Reviewed By: goldfire, simonpj
      
      Subscribers: monoidal, rwbarton, carter
      
      GHC Trac Issues: #15572
      
      Differential Revision: https://phabricator.haskell.org/D5112
      c46a5f20
  9. 27 Aug, 2018 3 commits
    • Ryan Scott's avatar
      Don't reify redundant class method tyvars/contexts · 6e765aeb
      Ryan Scott authored
      Summary:
      Currently, reifying classes produces class methods with
      redundant tyvars and class contexts in their type signatures, such
      as in the following:
      
      ```lang=haskell
      class C a where
        method :: forall a. C a => a
      ```
      
      Fixing this is very straightforward: just apply `tcSplitMethodTy` to
      the type of each class method to lop off the redundant parts.
      
      It's possible that this could break some TH code in the wild that
      assumes the existence of these tyvars and class contexts, so I'll
      advertise this change in the release notes just to be safe.
      
      Test Plan: make test TEST="TH_reifyDecl1 T9064 T10891 T14888"
      
      Reviewers: goldfire, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, carter
      
      GHC Trac Issues: #15551
      
      Differential Revision: https://phabricator.haskell.org/D5088
      6e765aeb
    • Ryan Scott's avatar
      Fix #15502 by not casting to Int during TH conversion · 7a3cda53
      Ryan Scott authored
      Summary:
      When turning an `IntegerL` to an `IntegralLit` during TH
      conversion, we were stupidly casting an `Integer` to an `Int` in
      order to determine how it should be pretty-printed. Unsurprisingly,
      this causes problems when the `Integer` doesn't lie within the bounds
      of an `Int`, as demonstrated in #15502.
      
      The fix is simple: don't cast to an `Int`.
      
      Test Plan: make test TEST=T15502
      
      Reviewers: bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, carter
      
      GHC Trac Issues: #15502
      
      Differential Revision: https://phabricator.haskell.org/D5089
      7a3cda53
    • Ryan Scott's avatar
      Fix #15550 by quoting RULE names during TH conversion · 5e6cf2a9
      Ryan Scott authored
      Summary:
      When converting a `RuleP` to a GHC source `RuleD` during TH
      conversion, we were stupidly not double-quoting the name of the rule.
      Easily fixed.
      
      Test Plan: make test TEST=T15550
      
      Reviewers: goldfire, bgamari, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, rwbarton, carter
      
      GHC Trac Issues: #15550
      
      Differential Revision: https://phabricator.haskell.org/D5090
      5e6cf2a9
  10. 14 Aug, 2018 1 commit
    • Ryan Scott's avatar
      Properly designate LambdaCase alts as CaseAlt in TH · 32008a9d
      Ryan Scott authored
      Summary:
      When `\case` expressions are parsed normally, their
      alternatives are marked as `CaseAlt` (which means that they are
      pretty-printed without a `\` character in front of them, unlike for
      lambda expressions). However, `\case` expressions created by way of
      Template Haskell (in `Convert`) inconsistently designated the case
      alternatives as `LambdaExpr`, causing them to be pretty-printed
      poorly (as shown in #15518). The fix is simple: use `CaseAlt`
      consistently.
      
      Test Plan: make test TEST=T15518
      
      Reviewers: goldfire, bgamari
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15518
      
      Differential Revision: https://phabricator.haskell.org/D5069
      32008a9d
  11. 02 Aug, 2018 1 commit
    • Richard Eisenberg's avatar
      Remove decideKindGeneralisationPlan · c955a514
      Richard Eisenberg authored
      TypeInType came with a new function: decideKindGeneralisationPlan.
      This type-level counterpart to the term-level decideGeneralisationPlan
      chose whether or not a kind should be generalized. The thinking was
      that if `let` should not be generalized, then kinds shouldn't either
      (under the same circumstances around -XMonoLocalBinds).
      
      However, this is too conservative -- the situation described in the
      motivation for "let should be be generalized" does not occur in types.
      
      This commit thus removes decideKindGeneralisationPlan, always
      generalizing.
      
      One consequence is that tc_hs_sig_type_and_gen no longer calls
      solveEqualities, which reports all unsolved constraints, instead
      relying on the solveLocalEqualities in tcImplicitTKBndrs. An effect
      of this is that reporing kind errors gets delayed more frequently.
      This seems to be a net benefit in error reporting; often, alongside
      a kind error, the type error is now reported (and users might find
      type errors easier to understand).
      
      Some of these errors ended up at the top level, where it was
      discovered that the GlobalRdrEnv containing the definitions in the
      local module was not in the TcGblEnv, and thus errors were reported
      with qualified names unnecessarily. This commit rejiggers some of
      the logic around captureTopConstraints accordingly.
      
      One error message (typecheck/should_fail/T1633)
      is a regression, mentioning the name of a default method. However,
      that problem is already reported as #10087, its solution is far from
      clear, and so I'm not addressing it here.
      
      This commit fixes #15141. As it's an internal refactor, there is
      no concrete test case for it.
      
      Along the way, we no longer need the hsib_closed field of
      HsImplicitBndrs (it was used only in decideKindGeneralisationPlan)
      and so it's been removed, simplifying the datatype structure.
      
      Along the way, I removed code in the validity checker that looks
      at coercions. This isn't related to this patch, really (though
      it was, at one point), but it's an improvement, so I kept it.
      
      This updates the haddock submodule.
      c955a514
  12. 01 Aug, 2018 1 commit
    • Richard Eisenberg's avatar
      Remove the type-checking knot. · f8618a9b
      Richard Eisenberg authored
      Bug #15380 hangs because a knot-tied TyCon ended up in a kind.
      Looking at the code in tcInferApps, I'm amazed this hasn't happened
      before! I couldn't think of a good way to fix it (with dependent
      types, we can't really keep types out of kinds, after all), so
      I just went ahead and removed the knot.
      
      This was remarkably easy to do. In tcTyVar, when we find a TcTyCon,
      just use it. (Previously, we looked up the knot-tied TyCon and used
      that.) Then, during the final zonk, replace TcTyCons with the real,
      full-blooded TyCons in the global environment. It's all very easy.
      
      The new bit is explained in the existing
      Note [Type checking recursive type and class declarations]
      in TcTyClsDecls.
      
      Naturally, I removed various references to the knot and the
      zonkTcTypeInKnot (and related) functions. Now, we can print types
      during type checking with abandon!
      
      NB: There is a teensy error message regression with this patch,
      around the ordering of quantified type variables. This ordering
      problem is fixed (I believe) with the patch for #14880. The ordering
      affects only internal variables that cannot be instantiated with
      any kind of visible type application.
      
      There is also a teensy regression around the printing of types
      in TH splices. I think this is really a TH bug and will file
      separately.
      
      Test case: dependent/should_fail/T15380
      f8618a9b
  13. 27 Jul, 2018 2 commits
    • Michael Sloan's avatar
      Fail instead of panic-ing when qAddTopDecls has conversion error · 774f366e
      Michael Sloan authored
      See https://ghc.haskell.org/trac/ghc/ticket/14627 for an example where
      GHC panics when using qAddTopDecls on [d| f = Bool |]. Instead, it
      should be a normal error message, and that's what this change is for. It
      does not entirely resolve Trac#14627, since "Illegal variable name:
      'bool'" isn't a very good error for this cirumstance.
      
      Test Plan: Manually tested.
      
      Reviewers: goldfire, bgamari
      
      Reviewed By: goldfire
      
      Subscribers: rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4914
      774f366e
    • Simon Peyton Jones's avatar
      Refactor (~) to reduce the suerpclass stack · f265008f
      Simon Peyton Jones authored
      The constraint (~) used to be (effectively):
        class a ~~ b => (a :: k) ~ (b :: k)
      
      but, with this patch, it is now defined uniformly with
      (~~) and Coercible like this:
        class a ~# b => (a :: k) ~ (b :: k)
      
      Result:
        * One less superclass selection when goinng from (~) to (~#)
          Better for compile time and better for debugging with -ddump-simpl
      
        * The code for (~), (~~), and Coercible looks uniform, and appears
          together, e.g. in TysWiredIn and ClsInst.matchGlobalInst.
          Previously the code for (~) was different, and unique.
      
      Not only is this simpler, but it also makes the compiler a bit faster;
        T12227: 9% less allocation
        T12545: 7% less allocation
      
      This patch fixes Trac #15421
      f265008f
  14. 22 Jul, 2018 1 commit
  15. 16 Jul, 2018 1 commit
    • Vladislav Zavialov's avatar
      Do not imply NoStarIsType by TypeOperators/TypeInType · 65c186f0
      Vladislav Zavialov authored
      Implementation of the "Embrace TypeInType" proposal was done according
      to the spec, which specified that TypeOperators must imply NoStarIsType.
      This implication was meant to prevent breakage and to be removed in 2
      releases.  However, compiling head.hackage has shown that this
      implication only magnified the breakage, so there is no reason to have
      it in the first place.
      
      To remain in compliance with the three-release policy, we add a
      workaround to define the (*) type operator even when -XStarIsType is on.
      
      Test Plan: ./validate
      
      Reviewers: bgamari, RyanGlScott, goldfire, phadej, hvr
      
      Reviewed By: bgamari, RyanGlScott
      
      Subscribers: harpocrates, rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4865
      65c186f0
  16. 12 Jul, 2018 2 commits
  17. 06 Jul, 2018 1 commit
    • Michael Sloan's avatar
      Add a broken test for lingering state from TH unique names #9693 · fbe162f5
      Michael Sloan authored
      The stderr output is
      
      ```
      Loading with T9693_initial.hs
      
      T9693_main.hs:4:1:
          Same exact name in multiple name-spaces:
            type constructor or class ‘X’, declared at: T9693_main.hs:4:1
            data constructor ‘X’, declared at: T9693_main.hs:4:1
            Probable cause: you bound a unique Template Haskell name (NameU),
            perhaps via newName, in different name-spaces.
            If that's it, then -ddump-splices might be useful
      Reloading with T9693_modified.hs
      
      T9693_main.hs:1:1:
          Data constructor ‘X’ used as a type constructor
      ```
      
      The strange thing is that the modified version uses (mkName "X"), which should
      be fine for simultaneous use in both a data constructor and type constructor.
      Indeed, on a fresh load, the modified version works fine. So there is some sort
      of state left over from the prior load when (newName "X") was used.
      
      Test Plan: testsuite/tests/th/T9693.script
      
      Reviewers: bgamari, sighingnow, RyanGlScott
      
      Reviewed By: sighingnow, RyanGlScott
      
      Subscribers: RyanGlScott, sighingnow, rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4926
      fbe162f5
  18. 05 Jul, 2018 2 commits
  19. 04 Jul, 2018 1 commit
  20. 19 Jun, 2018 1 commit
  21. 15 Jun, 2018 1 commit
    • Sylvain Henry's avatar
      Built-in Natural literals in Core · fe770c21
      Sylvain Henry authored
      Add support for built-in Natural literals in Core.
      
      - Replace MachInt,MachWord, LitInteger, etc. with a single LitNumber
        constructor with a LitNumType field
      - Support built-in Natural literals
      - Add desugar warning for negative literals
      - Move Maybe(..) from GHC.Base to GHC.Maybe for module dependency
        reasons
      
      This patch introduces only a few rules for Natural literals (compared
      to Integer's rules). Factorization of the built-in rules for numeric
      literals will be done in another patch as this one is already big to
      review.
      
      Test Plan:
        validate
        test build with integer-simple
      
      Reviewers: hvr, bgamari, goldfire, Bodigrim, simonmar
      
      Reviewed By: bgamari
      
      Subscribers: phadej, simonpj, RyanGlScott, carter, hsyl20, rwbarton,
      thomie
      
      GHC Trac Issues: #14170, #14465
      
      Differential Revision: https://phabricator.haskell.org/D4212
      fe770c21
  22. 14 Jun, 2018 1 commit
    • Vladislav Zavialov's avatar
      Embrace -XTypeInType, add -XStarIsType · d650729f
      Vladislav Zavialov authored
      Summary:
      Implement the "Embrace Type :: Type" GHC proposal,
      .../ghc-proposals/blob/master/proposals/0020-no-type-in-type.rst
      
      GHC 8.0 included a major change to GHC's type system: the Type :: Type
      axiom. Though casual users were protected from this by hiding its
      features behind the -XTypeInType extension, all programs written in GHC
      8+ have the axiom behind the scenes. In order to preserve backward
      compatibility, various legacy features were left unchanged. For example,
      with -XDataKinds but not -XTypeInType, GADTs could not be used in types.
      Now these restrictions are lifted and -XTypeInType becomes a redundant
      flag that will be eventually deprecated.
      
      * Incorporate the features currently in -XTypeInType into the
        -XPolyKinds and -XDataKinds extensions.
      * Introduce a new extension -XStarIsType to control how to parse * in
        code and whether to print it in error messages.
      
      Test Plan: Validate
      
      Reviewers: goldfire, hvr, bgamari, alanz, simonpj
      
      Reviewed By: goldfire, simonpj
      
      Subscribers: rwbarton, thomie, mpickering, carter
      
      GHC Trac Issues: #15195
      
      Differential Revision: https://phabricator.haskell.org/D4748
      d650729f
  23. 11 Jun, 2018 1 commit
  24. 10 Jun, 2018 1 commit
  25. 07 Jun, 2018 1 commit
  26. 30 May, 2018 1 commit
    • Matthías Páll Gissurarson's avatar
      Improved Valid Hole Fits · e0b44e2e
      Matthías Páll Gissurarson authored
      I've changed the name from `Valid substitutions` to `Valid hole fits`,
      since "substitution" already has a well defined meaning within the
      theory. As part of this change, the flags and output is reanamed, with
      substitution turning into hole-fit in most cases. "hole fit" was already
      used internally in the code, it's clear and shouldn't cause any
      confusion.
      
      In this update, I've also reworked how we manage side-effects in the
      hole we are considering.
      
      This allows us to consider local bindings such as where clauses and
      arguments to functions, suggesting e.g. `a` for `head (x:xs) where head
      :: [a] -> a`.
      
      It also allows us to find suggestions such as `maximum` for holes of
      type `Ord a => a -> [a]`, and `max` when looking for a match for the
      hole in `g = foldl1 _`, where `g :: Ord a => [a] -> a`.
      
      We also show much improved output for refinement hole fits, and
      fixes #14990. We now show the correct type of the function, but we also
      now show what the arguments to the function should be e.g. `foldl1 (_ ::
      Integer -> Integer -> Integer)` when looking for `[Integer] -> Integer`.
      
      I've moved the bulk of the code from `TcErrors.hs` to a new file,
      `TcHoleErrors.hs`, since it was getting too big to not live on it's own.
      
      This addresses the considerations raised in #14969, and takes proper
      care to set the `tcLevel` of the variables to the right level before
      passing it to the simplifier.
      
      We now also zonk the suggestions properly, which improves the output of
      the refinement hole fits considerably.
      
      This also filters out suggestions from the `GHC.Err` module, since even
      though `error` and `undefined` are indeed valid hole fits, they are
      "trivial", and almost never useful to the user.
      
      We now find the hole fits using the proper manner, namely by solving
      nested implications. This entails that the givens are passed along using
      the implications the hole was nested in, which in turn should mean that
      there will be fewer weird bugs in the typed holes.
      
      I've also added a new sorting method (as suggested by SPJ) and sort by
      the size of the types needed to turn the hole fits into the type of the
      hole. This gives a reasonable approximation to relevance, and is much
      faster than the subsumption check. I've also added a flag to toggle
      whether to use this new sorting algorithm (as is done by default) or the
      subsumption algorithm. This fixes #14969
      
      I've also added documentation for these new flags and update the
      documentation according to the new output.
      
      Reviewers: bgamari, goldfire
      
      Reviewed By: bgamari
      
      Subscribers: simonpj, rwbarton, thomie, carter
      
      GHC Trac Issues: #14969, #14990, #10946
      
      Differential Revision: https://phabricator.haskell.org/D4444
      e0b44e2e
  27. 24 May, 2018 1 commit
    • Ryan Scott's avatar
      Check for mismatched class methods during typechecking · 1879d9d2
      Ryan Scott authored
      Summary:
      Template Haskell provides a wormhole through which you can
      sneak methods that don't belong to a class into an instance for that
      class, bypassing the renamer's validity checks. The solution adopted
      here is to mirror the treatment for associated type family instances,
      which have an additional check in the typechecker which catch
      mismatched associated type families that were snuck through using
      Template Haskell. I've put a similar check for class methods into
      `tcMethods`.
      
      Test Plan: make test TEST=T12387
      
      Reviewers: bgamari, simonpj
      
      Reviewed By: bgamari, simonpj
      
      Subscribers: simonpj, rwbarton, thomie, carter
      
      GHC Trac Issues: #12387
      
      Differential Revision: https://phabricator.haskell.org/D4710
      1879d9d2
  28. 20 May, 2018 1 commit
  29. 14 May, 2018 1 commit
    • Ryan Scott's avatar
      Fix #14875 by introducing PprPrec, and using it · 21e1a00c
      Ryan Scott authored
      Trying to determine when to insert parentheses during TH
      conversion is a bit of a mess. There is an assortment of functions
      that try to detect this, such as:
      
      * `hsExprNeedsParens`
      * `isCompoundHsType`
      * `hsPatNeedsParens`
      * `isCompoundPat`
      * etc.
      
      To make things worse, each of them have slightly different semantics.
      Plus, they don't work well in the presence of explicit type
      signatures, as #14875 demonstrates.
      
      All of these problems can be alleviated with the use of an explicit
      precedence argument (much like what `showsPrec` currently does). To
      accomplish this, I introduce a new `PprPrec` data type, and define
      standard predences for things like function application, infix
      operators, function arrows, and explicit type signatures (that last
      one is new). I then added `PprPrec` arguments to the various
      `-NeedsParens` functions, and use them to make smarter decisions
      about when things need to be parenthesized.
      
      A nice side effect is that functions like `isCompoundHsType` are
      now completely unneeded, since they're simply aliases for
      `hsTypeNeedsParens appPrec`. As a result, I did a bit of refactoring
      to remove these sorts of functions. I also did a pass over various
      utility functions in GHC for constructing AST forms and used more
      appropriate precedences where convenient.
      
      Along the way, I also ripped out the existing `TyPrec`
      data type (which was tailor-made for pretty-printing `Type`s) and
      replaced it with `PprPrec` for consistency.
      
      Test Plan: make test TEST=T14875
      
      Reviewers: alanz, goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie, carter
      
      GHC Trac Issues: #14875
      
      Differential Revision: https://phabricator.haskell.org/D4688
      21e1a00c