1. 22 Feb, 2019 1 commit
  2. 18 Feb, 2019 1 commit
    • Simon Peyton Jones's avatar
      Get rid of tcm_smart from TyCoMapper · 1f1b9e35
      Simon Peyton Jones authored
      Following a succession of refactorings of the type checker,
      culminating in the patch
             Make a smart mkAppTyM
      we have got rid of mkNakedAppTy etc.  And that in turn
      meant that the tcm_smart field of the generic TyCoMapper
      (in Type.hs) was entirely unused.  It was always set to True.
      
      So this patch just gets rid of it completely.  Less code,
      less complexity, and more efficient because fewer higher-order
      function calls.  Everyone wins.
      
      No change in behaviour; this does not cure any bugs!
      1f1b9e35
  3. 14 Feb, 2019 2 commits
    • Simon Peyton Jones's avatar
      Fail fast in solveLocalEqualities · 5c1f268e
      Simon Peyton Jones authored
      This patch makes us fail fast in TcSimplify.solveLocalEqualities,
      and in TcHsType.tc_hs_sig_type, if there are insoluble constraints.
      
      Previously we ploughed on even if there were insoluble constraints,
      leading to a cascade of hard-to-understand type errors. Failing
      eagerly is much better; hence a lot of testsuite error message
      changes.  Eg if we have
                f :: [Maybe] -> blah
                f xs = e
      then trying typecheck 'f x = e' with an utterly bogus type
      is just asking for trouble.
      
      I can't quite remember what provoked me to make this change,
      but I think the error messages are notably improved, by
      removing confusing clutter and focusing on the real error.
      5c1f268e
    • Simon Peyton Jones's avatar
      Make a smart mkAppTyM · 68278382
      Simon Peyton Jones authored
      This patch finally delivers on Trac #15952.  Specifically
      
      * Completely remove Note [The tcType invariant], along with
        its complicated consequences (IT1-IT6).
      
      * Replace Note [The well-kinded type invariant] with:
      
            Note [The Purely Kinded Type Invariant (PKTI)]
      
      * Instead, establish the (PKTI) in TcHsType.tcInferApps,
        by using a new function mkAppTyM when building a type
        application.  See Note [mkAppTyM].
      
      * As a result we can remove the delicate mkNakedXX functions
        entirely.  Specifically, mkNakedCastTy retained lots of
        extremly delicate Refl coercions which just cluttered
        everything up, and(worse) were very vulnerable to being
        silently eliminated by (say) substTy. This led to a
        succession of bug reports.
      
      The result is noticeably simpler to explain, simpler
      to code, and Richard and I are much more confident that
      it is correct.
      
      It does not actually fix any bugs, but it brings us closer.
      E.g. I hoped it'd fix #15918 and #15799, but it doesn't quite
      do so.  However, it makes it much easier to fix.
      
      I also did a raft of other minor refactorings:
      
      * Use tcTypeKind consistently in the type checker
      
      * Rename tcInstTyBinders to tcInvisibleTyBinders,
        and refactor it a bit
      
      * Refactor tcEqType, pickyEqType, tcEqTypeVis
        Simpler, probably more efficient.
      
      * Make zonkTcType zonk TcTyCons, at least if they have
        any free unification variables -- see zonk_tc_tycon
        in TcMType.zonkTcTypeMapper.
      
        Not zonking these TcTyCons was actually a bug before.
      
      * Simplify try_to_reduce_no_cache in TcFlatten (a lot)
      
      * Combine checkExpectedKind and checkExpectedKindX.
        And then combine the invisible-binder instantation code
        Much simpler now.
      
      * Fix a little bug in TcMType.skolemiseQuantifiedTyVar.
        I'm not sure how I came across this originally.
      
      * Fix a little bug in TyCoRep.isUnliftedRuntimeRep
        (the ASSERT was over-zealous).  Again I'm not certain
        how I encountered this.
      
      * Add a missing solveLocalEqualities in
        TcHsType.tcHsPartialSigType.
        I came across this when trying to get level numbers
        right.
      68278382
  4. 08 Feb, 2019 1 commit
    • Alan Zimmerman's avatar
      API Annotations: AnnAt disconnected for TYPEAPP · cbfc9fca
      Alan Zimmerman authored
      For the code
      
          type family F1 (a :: k) (f :: k -> Type) :: Type where
            F1 @Peano a f = T @Peano f a
      
      the API annotation for the first @ is not attached to a SourceSpan in
      the ParsedSource
      
      Closes #16236
      cbfc9fca
  5. 28 Jan, 2019 1 commit
  6. 08 Jan, 2019 1 commit
    • Ryan Scott's avatar
      Be pickier about unsaturated synonyms in :kind · 6b70cf61
      Ryan Scott authored
      Summary:
      We currently permit any and all uses of unsaturated type
      synonyms and type families in GHCi's `:kind` command, which allows
      strange interactions like this one:
      
      ```
      > :set -XTypeFamilies -XPolyKinds
      > type family Id (a :: k)
      > type instance Id a = a
      > type Foo x = Maybe
      > :kind! Id Foo
      ```
      
      This is probably a stretch too far, so this patch moves to disallow
      unsaturated synonyms that aren't at the top level (we still want to
      allow `:kind Id`, for instance). We do this by augmenting `GhciCtxt`
      with an additional `Bool` field to indicate if we are at the
      outermost level of the type being passed to `:kind` or not. See
      `Note [Unsaturated type synonyms in GHCi]` in `TcValidity` for the
      full story.
      
      Test Plan: make test TEST=T16013
      
      Reviewers: goldfire, bgamari
      
      Reviewed By: goldfire
      
      Subscribers: simonpj, goldfire, rwbarton, carter
      
      GHC Trac Issues: #16013
      
      Differential Revision: https://phabricator.haskell.org/D5471
      6b70cf61
  7. 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
  8. 20 Dec, 2018 1 commit
  9. 03 Dec, 2018 1 commit
    • Simon Peyton Jones's avatar
      Introduce tcTypeKind, and use it · 03d48526
      Simon Peyton Jones authored
      In the type checker Constraint and * are distinct; and the function
      that takes the kind of a type should respect that distinction
      (Trac #15971).
      
      This patch implements the change:
      
      * Introduce Type.tcTypeKind, and use it throughout the type
        inference engine
      
      * Add new Note [Kinding rules for types] for the kinding
        rules, especially for foralls.
      
      * Redefine
          isPredTy ty = tcIsConstraintKind (tcTypeKind ty)
        (it had a much more complicated definition before)
      
      Some miscellaneous refactoring
      
      * Get rid of TyCoRep.isTYPE, Kind.isTYPEApp,
        in favour of TyCoRep.kindRep, kindRep_maybe
      
      * Rename Type.getRuntimeRepFromKind_maybe
        to getRuntimeRep_maybe
      
      I did some spot-checks on compiler perf, and it really doesn't
      budge (as expected).
      03d48526
  10. 29 Nov, 2018 1 commit
    • Simon Peyton Jones's avatar
      Taming the Kind Inference Monster · 2257a86d
      Simon Peyton Jones authored
      My original goal was (Trac #15809) to move towards using level numbers
      as the basis for deciding which type variables to generalise, rather
      than searching for the free varaibles of the environment.  However
      it has turned into a truly major refactoring of the kind inference
      engine.
      
      Let's deal with the level-numbers part first:
      
      * Augment quantifyTyVars to calculate the type variables to
        quantify using level numbers, and compare the result with
        the existing approach.  That is; no change in behaviour,
        just a WARNing if the two approaches give different answers.
      
      * To do this I had to get the level number right when calling
        quantifyTyVars, and this entailed a bit of care, especially
        in the code for kind-checking type declarations.
      
      * However, on the way I was able to eliminate or simplify
        a number of calls to solveEqualities.
      
      This work is incomplete: I'm not /using/ level numbers yet.
      When I subsequently get rid of any remaining WARNings in
      quantifyTyVars, that the level-number answers differ from
      the current answers, then I can rip out the current
      "free vars of the environment" stuff.
      
      Anyway, this led me into deep dive into kind inference for type and
      class declarations, which is an increasingly soggy part of GHC.
      Richard already did some good work recently in
      
         commit 5e45ad10
         Date:   Thu Sep 13 09:56:02 2018 +0200
      
          Finish fix for #14880.
      
          The real change that fixes the ticket is described in
          Note [Naughty quantification candidates] in TcMType.
      
      but I kept turning over stones. So this patch has ended up
      with a pretty significant refactoring of that code too.
      
      Kind inference for types and classes
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      * Major refactoring in the way we generalise the inferred kind of
        a TyCon, in kcTyClGroup.  Indeed, I made it into a new top-level
        function, generaliseTcTyCon.  Plus a new Note to explain it
        Note [Inferring kinds for type declarations].
      
      * We decided (Trac #15592) not to treat class type variables specially
        when dealing with Inferred/Specified/Required for associated types.
        That simplifies things quite a bit. I also rewrote
        Note [Required, Specified, and Inferred for types]
      
      * Major refactoring of the crucial function kcLHsQTyVars:
        I split it into
             kcLHsQTyVars_Cusk  and  kcLHsQTyVars_NonCusk
        because the two are really quite different. The CUSK case is
        almost entirely rewritten, and is much easier because of our new
        decision not to treat the class variables specially
      
      * I moved all the error checks from tcTyClTyVars (which was a bizarre
        place for it) into generaliseTcTyCon and/or the CUSK case of
        kcLHsQTyVars.  Now tcTyClTyVars is extremely simple.
      
      * I got rid of all the all the subtleties in tcImplicitTKBndrs. Indeed
        now there is no difference between tcImplicitTKBndrs and
        kcImplicitTKBndrs; there is now a single bindImplicitTKBndrs.
        Same for kc/tcExplicitTKBndrs.  None of them monkey with level
        numbers, nor build implication constraints.  scopeTyVars is gone
        entirely, as is kcLHsQTyVarBndrs. It's vastly simpler.
      
        I found I could get rid of kcLHsQTyVarBndrs entirely, in favour of
        the bnew bindExplicitTKBndrs.
      
      Quantification
      ~~~~~~~~~~~~~~
      * I now deal with the "naughty quantification candidates"
        of the previous patch in candidateQTyVars, rather than in
        quantifyTyVars; see Note [Naughty quantification candidates]
        in TcMType.
      
        I also killed off closeOverKindsCQTvs in favour of the same
        strategy that we use for tyCoVarsOfType: namely, close over kinds
        at the occurrences.
      
        And candidateQTyVars no longer needs a gbl_tvs argument.
      
      * Passing the ContextKind, rather than the expected kind itself,
        to tc_hs_sig_type_and_gen makes it easy to allocate the expected
        result kind (when we are in inference mode) at the right level.
      
      Type families
      ~~~~~~~~~~~~~~
      * I did a major rewrite of the impenetrable tcFamTyPats. The result
        is vastly more comprehensible.
      
      * I got rid of kcDataDefn entirely, quite a big function.
      
      * I re-did the way that checkConsistentFamInst works, so
        that it allows alpha-renaming of invisible arguments.
      
      * The interaction of kind signatures and family instances is tricky.
          Type families: see Note [Apparently-nullary families]
          Data families: see Note [Result kind signature for a data family instance]
                         and Note [Eta-reduction for data families]
      
      * The consistent instantation of an associated type family is tricky.
        See Note [Checking consistent instantiation] and
            Note [Matching in the consistent-instantation check]
        in TcTyClsDecls.  It's now checked in TcTyClsDecls because that is
        when we have the relevant info to hand.
      
      * I got tired of the compromises in etaExpandFamInst, so I did the
        job properly by adding a field cab_eta_tvs to CoAxBranch.
        See Coercion.etaExpandCoAxBranch.
      
      tcInferApps and friends
      ~~~~~~~~~~~~~~~~~~~~~~~
      * I got rid of the mysterious and horrible ClsInstInfo argument
        to tcInferApps, checkExpectedKindX, and various checkValid
        functions.  It was horrible!
      
      * I got rid of [Type] result of tcInferApps.  This list was used
        only in tcFamTyPats, when checking the LHS of a type instance;
        and if there is a cast in the middle, the list is meaningless.
        So I made tcInferApps simpler, and moved the complexity
        (not much) to tcInferApps.
      
        Result: tcInferApps is now pretty comprehensible again.
      
      * I refactored the many function in TcMType that instantiate skolems.
      
      Smaller things
      
      * I rejigged the error message in checkValidTelescope; I think it's
        quite a bit better now.
      
      * checkValidType was not rejecting constraints in a kind signature
           forall (a :: Eq b => blah). blah2
        That led to further errors when we then do an ambiguity check.
        So I make checkValidType reject it more aggressively.
      
      * I killed off quantifyConDecl, instead calling kindGeneralize
        directly.
      
      * I fixed an outright bug in tyCoVarsOfImplic, where we were not
        colleting the tyvar of the kind of the skolems
      
      * Renamed ClsInstInfo to AssocInstInfo, and made it into its
        own data type
      
      * Some fiddling around with pretty-printing of family
        instances which was trickier than I thought.  I wanted
        wildcards to print as plain "_" in user messages, although
        they each need a unique identity in the CoAxBranch.
      
      Some other oddments
      
      * Refactoring around the trace messages from reportUnsolved.
      * A bit of extra tc-tracing in TcHsSyn.commitFlexi
      
      This patch fixes a raft of bugs, and includes tests for them.
      
       * #14887
       * #15740
       * #15764
       * #15789
       * #15804
       * #15817
       * #15870
       * #15874
       * #15881
      2257a86d
  11. 24 Nov, 2018 1 commit
  12. 01 Nov, 2018 1 commit
    • Richard Eisenberg's avatar
      Actually fail in failIfEmitsConstraints · 74ed9c1c
      Richard Eisenberg authored
      The function TcHsType.failIfEmitsConstraints says that it fails.
      It even does so in its name. But it didn't! It *reported* constraints
      but didn't fail. Now it does.
      
      This is important in tcHsClsInstType; see the comments therein.
      
      This was discovered while looking at #15797, but that ticket
      requires visible kind application to exhibit the bug; the test
      case will come with the patch for #12045.
      74ed9c1c
  13. 29 Oct, 2018 1 commit
    • Tobias Dammers's avatar
      Finish fix for #14880. · 5e45ad10
      Tobias Dammers authored
      The real change that fixes the ticket is described in
      Note [Naughty quantification candidates] in TcMType.
      
      Fixing this required reworking candidateQTyVarsOfType, the function
      that extracts free variables as candidates for quantification.
      One consequence is that we now must be more careful when quantifying:
      any skolems around must be quantified manually, and quantifyTyVars
      will now only quantify over metavariables. This makes good sense,
      as skolems are generally user-written and are listed in the AST.
      
      As a bonus, we now have more control over the ordering of such
      skolems.
      
      Along the way, this commit fixes #15711 and refines the fix
      to #14552 (by accepted a program that was previously rejected,
      as we can now accept that program by zapping variables to Any).
      
      This commit also does a fair amount of rejiggering kind inference
      of datatypes. Notably, we now can skip the generalization step
      in kcTyClGroup for types with CUSKs, because we get the
      kind right the first time. This commit also thus fixes #15743 and
       #15592, which both concern datatype kind generalisation.
      (#15591 is also very relevant.) For this aspect of the commit, see
      Note [Required, Specified, and Inferred in types] in TcTyClsDecls.
      
      Test cases: dependent/should_fail/T14880{,-2},
                  dependent/should_fail/T15743[cd]
                  dependent/should_compile/T15743{,e}
                  ghci/scripts/T15743b
                  polykinds/T15592
                  dependent/should_fail/T15591[bc]
                  ghci/scripts/T15591
      5e45ad10
  14. 28 Oct, 2018 1 commit
    • Ningning Xie's avatar
      Fix `:k` command: add validity checking · c4a876d5
      Ningning Xie authored
      Summary:
      This patch fixes #15806, where we found that the `:k` command in GHCi
      misses a validity checking for the type.
      
      Missing validity checking causes `:k` to accept types that are not validated.
      For example, `:k (Maybe (forall a. a -> a))` (incorrectly) returns `*`, while
      impredictivity of type instantiation shouldn't be allowed.
      
      Test Plan: ./validate
      
      Reviewers: simonpj, goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15806
      
      Differential Revision: https://phabricator.haskell.org/D5265
      c4a876d5
  15. 25 Oct, 2018 1 commit
    • Simon Peyton Jones's avatar
      Remove a zonkTcTyVarToTyVar · 29978ef1
      Simon Peyton Jones authored
      This patch fixes Trac #15778 by removing a zonkTcTyVarToTyVar
      from tcHsSigType.
      
      Nww that a pattern-bound type variable can refer to a type, it's
      obvoiusly wrong to expect it to be a TyVar!  Moreover, that zonk
      is entirely unnecessary.
      
      I added a new Note [Type variables in the type environment]
      in TcRnTypes
      29978ef1
  16. 01 Oct, 2018 1 commit
    • Ryan Scott's avatar
      Quantify class variables first in associated families' kinds · a57fa247
      Ryan Scott authored
      Summary:
      Previously, `kcLHsQTyVars` would always quantify class-bound
      variables invisibly in the kinds of associated types, resulting in
      #15591. We counteract this by explicitly passing the class-bound
      variables to `kcLHsQTyVars` and quantifying over the ones that are
      mentioned in the associated type such that (1) they are specified,
      and (2) they come before other kind variables.
      See `Note [Kind variable ordering for associated types]`.
      
      Test Plan: make test TEST=T15591
      
      Reviewers: goldfire, simonpj, bgamari
      
      Reviewed By: simonpj
      
      Subscribers: rwbarton, carter
      
      GHC Trac Issues: #15591
      
      Differential Revision: https://phabricator.haskell.org/D5159
      a57fa247
  17. 15 Sep, 2018 1 commit
    • Ningning Xie's avatar
      Coercion Quantification · ea5ade34
      Ningning Xie authored
      This patch corresponds to #15497.
      
      According to https://ghc.haskell.org/trac/ghc/wiki/DependentHaskell/Phase2,
       we would like to have coercion quantifications back. This will
      allow us to migrate (~#) to be homogeneous, instead of its current
      heterogeneous definition. This patch is (lots of) plumbing only. There
      should be no user-visible effects.
      
      An overview of changes:
      
      - Both `ForAllTy` and `ForAllCo` can quantify over coercion variables,
      but only in *Core*. All relevant functions are updated accordingly.
      - Small changes that should be irrelevant to the main task:
          1. removed dead code `mkTransAppCo` in Coercion
          2. removed out-dated Note Computing a coercion kind and
             roles in Coercion
          3. Added `Eq4` in Note Respecting definitional equality in
             TyCoRep, and updated `mkCastTy` accordingly.
          4. Various updates and corrections of notes and typos.
      - Haddock submodule needs to be changed too.
      
      Acknowledgments:
      This work was completed mostly during Ningning Xie's Google Summer
      of Code, sponsored by Google. It was advised by Richard Eisenberg,
      supported by NSF grant 1704041.
      
      Test Plan: ./validate
      
      Reviewers: goldfire, simonpj, bgamari, hvr, erikd, simonmar
      
      Subscribers: RyanGlScott, monoidal, rwbarton, carter
      
      GHC Trac Issues: #15497
      
      Differential Revision: https://phabricator.haskell.org/D5054
      ea5ade34
  18. 31 Aug, 2018 2 commits
    • Simon Peyton Jones's avatar
      Remove knot-tying bug in TcHsSyn.zonkTyVarOcc · 565ef4cc
      Simon Peyton Jones authored
      There was a subtle knot-tying bug in TcHsSyn.zonkTyVarOcc, revealed
      in Trac #15552.
      
      I fixed it by
      
      * Eliminating the short-circuiting optimisation in zonkTyVarOcc,
        instead adding a finite map to get sharing of zonked unification
        variables.
      
        See Note [Sharing when zonking to Type] in TcHsSyn
      
      * On the way I /added/ the short-circuiting optimisation to
        TcMType.zonkTcTyVar, which has no such problem.  This turned
        out (based on non-systematic measurements) to be a modest win.
      
        See Note [Sharing in zonking] in TcMType
      
      On the way I renamed some of the functions in TcHsSyn:
      
      * Ones ending in "X" (like zonkTcTypeToTypeX) take a ZonkEnv
      
      * Ones that do not end in "x" (like zonkTcTypeToType), don't.
        Instead they whiz up an empty ZonkEnv.
      565ef4cc
    • Richard Eisenberg's avatar
      5d3eb646
  19. 28 Aug, 2018 1 commit
    • Ryan Scott's avatar
      Rename kind vars in left-to-right order in bindHsQTyVars · 102284e7
      Ryan Scott authored
      Summary:
      When renaming kind variables in an `LHsQTyVars`, we were
      erroneously putting all of the kind variables in the binders
      //after// the kind variables in the body, resulting in #15568. The
      fix is simple: just swap the order of these two around.
      
      Test Plan: make test TEST=T15568
      
      Reviewers: simonpj, bgamari, goldfire
      
      Reviewed By: goldfire
      
      Subscribers: goldfire, rwbarton, carter
      
      GHC Trac Issues: #15568
      
      Differential Revision: https://phabricator.haskell.org/D5108
      102284e7
  20. 21 Aug, 2018 1 commit
    • Simon Peyton Jones's avatar
      Add a solveEqualities to tcClassDecl1 · 43b08cfb
      Simon Peyton Jones authored
      Trac #15505 showed that, when we have a type error, we
      could have an unfilled-in coercion hole.  We don't want an
      assertion error in that case.
      
      The underlying cause is that tcClassDecl1 should call
      solveEqualities to fully solve all top-level equalities
      (or fail in the attempt).
      
      I also refactored the ClassDecl case for tcTyClDecl1 into
      a new function tcClassDecl1.  That makes it symmetrical
      with the others.
      43b08cfb
  21. 17 Aug, 2018 1 commit
    • Joachim Breitner's avatar
      Rename SigTv to TyVarTv (#15480) · a50244c6
      Joachim Breitner authored
      because since #15050, these are no longer used in pattern SIGnatures,
      but still in other places where meta-variables should only be unified
      with TYpe VARiables.
      
      I also found mentions of `SigTv` in parts of the renamer and desugarer
      that do not seem to directly relate to `SigTv` as used in the type
      checker, but rather to uses of `forall a.` in type signatures. I renamed
      these to `ScopedTv`.
      
      Differential Revision: https://phabricator.haskell.org/D5074
      a50244c6
  22. 06 Aug, 2018 1 commit
  23. 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
  24. 01 Aug, 2018 2 commits
    • Vladislav Zavialov's avatar
      Fix #15415 and simplify tcWildCardBinders · 120cc9f8
      Vladislav Zavialov authored
      Test Plan: Validate
      
      Reviewers: goldfire, simonpj, bgamari
      
      Reviewed By: simonpj
      
      Subscribers: RyanGlScott, rwbarton, thomie, carter
      
      GHC Trac Issues: #15415
      
      Differential Revision: https://phabricator.haskell.org/D5022
      120cc9f8
    • 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
  25. 25 Jul, 2018 1 commit
    • Simon Peyton Jones's avatar
      Treat isConstraintKind more consistently · c5d31df7
      Simon Peyton Jones authored
      It turned out that we were not being consistent
      about our use of isConstraintKind.
      
      It's delicate, because the typechecker treats Constraint and Type as
      /distinct/, whereas they are the /same/ in the rest of the compiler
      (Trac #11715).
      
      And had it wrong, which led to Trac #15412.  This patch does the
      following:
      
      * Rename isConstraintKind      to tcIsConstraintKind
               returnsConstraintKind to tcReturnsConstraintKind
        to emphasise that they use the 'tcView' view of types.
      
      * Move these functions, and some related ones (tcIsLiftedTypeKind),
        from Kind.hs, to group together in Type.hs, alongside isPredTy.
      
      It feels very unsatisfactory that these 'tcX' functions live in Type,
      but it happens because isPredTy is called later in the compiler
      too.  But it's a consequence of the 'Constraint vs Type' dilemma.
      c5d31df7
  26. 17 Jul, 2018 1 commit
  27. 15 Jul, 2018 1 commit
    • Richard Eisenberg's avatar
      Don't mkNakedCastTy on something unsaturated · 15ce9b45
      Richard Eisenberg authored
      A recent commit added extra calls to mkNakedCastTy to satisfy
      Note [The tcType invariant]. However, some of these casts were
      being applied to unsaturated type family applications, which
      caused ASSERTion failures in TcFlatten later on. This patch
      is more judicious in using mkNakedCastTy to avoid this problem.
      15ce9b45
  28. 13 Jul, 2018 1 commit
  29. 11 Jul, 2018 1 commit
  30. 10 Jul, 2018 6 commits
    • Richard Eisenberg's avatar
      Note [Ordering of implicit variables] · 7f4dd888
      Richard Eisenberg authored
      This addresses #14808
      
      [ci skip]
      7f4dd888
    • Richard Eisenberg's avatar
      Expand and implement Note [The tcType invariant] · cf67e59a
      Richard Eisenberg authored
      Read that note -- it's necessary to make sure that we can
      always call typeKind without panicking. As discussed on #14873,
      there were more checks and zonking to do, implemented here.
      There are no known bugs fixed by this patch, but there are likely
      unknown ones.
      cf67e59a
    • Richard Eisenberg's avatar
      Kind-check CUSK associated types separately · 030211d2
      Richard Eisenberg authored
      Previously, we kind-checked associated types while while still
      figuring out the kind of a CUSK class. This caused trouble, as
      documented in Note [Don't process associated types in kcLHsQTyVars]
      in TcTyClsDecls. This commit moves this process after the initial
      kind of the class is determined.
      
      Fixes #15142.
      
      Test case: indexed-types/should_compile/T15142.hs
      030211d2
    • Simon Peyton Jones's avatar
      Add nakedSubstTy and use it in TcHsType.tcInferApps · 5067b205
      Simon Peyton Jones authored
      This was a tricky one.
      
      During type checking we maintain TcType:
         Note [The well-kinded type invariant]
      That is, types are well-kinded /without/ zonking.
      
      But in tcInferApps we were destroying that invariant by calling
      substTy, which in turn uses smart constructors, which eliminate
      apparently-redundant Refl casts.
      
      This is horribly hard to debug beause they really are Refls and
      so it "ought" to be OK to discard them. But it isn't, as the
      above Note describes in some detail.
      
      Maybe we should review the invariant?  But for now I just followed
      it, tricky thought it is.
      
      This popped up because (for some reason) when I fixed Trac #15343,
      that exposed this bug by making test polykinds/T14174a fail (in
      Trac #14174 which indeed has the same origin).
      
      So this patch fixes a long standing and very subtle bug.
      
      One interesting point: I defined nakedSubstTy in a few lines by
      using the generic mapType stuff.  I note that the "normal"
      TyCoRep.substTy does /not/ use mapType.  But perhaps it should:
      substTy has lots of $! strict applications in it, and they could
      all be eliminated just by useing the StrictIdentity monad.  And
      that'd make it much easier to experiment with switching between
      strict and lazy versions.
      5067b205
    • Simon Peyton Jones's avatar
      More tc-tracing · 03d72683
      Simon Peyton Jones authored
      And I added some HasDebugCallStack constraints to tcExpectedKind
      and related functions too.
      03d72683
    • Simon Peyton Jones's avatar
      Fix decompsePiCos and visible type application · aedbf7f1
      Simon Peyton Jones authored
      Trac #15343 was caused by two things
      
      First, in TcHsType.tcHsTypeApp, which deals with the type argment
      in visible type application, we were failing to call
      solveLocalEqualities. But the type argument is like a user type
      signature so it's at least inconsitent not to do so.
      
      I thought that would nail it.  But it didn't. It turned out that we
      were ended up calling decomposePiCos on a type looking like this
          (f |> co) Int
      
      where co :: (forall a. ty) ~ (t1 -> t2)
      
      Now, 'co' is insoluble, and we'll report that later.  But meanwhile
      we don't want to crash in decomposePiCos.
      
      My fix involves keeping track of the type on both sides of the
      coercion, and ensuring that the outer shape matches before
      decomposing.  I wish there was a simpler way to do this. But
      I think this one is at least robust.
      
      I suppose it is possible that the decomposePiCos fix would
      have cured the original report, but I'm leaving the one-line
      tcHsTypeApp fix in too because it just seems more consistent.
      aedbf7f1
  31. 25 Jun, 2018 1 commit
    • Simon Peyton Jones's avatar
      Refactor the kind-checking of tyvar binders · 9fc40c73
      Simon Peyton Jones authored
      The refactoring here is driven by the ghastly mess described in
      comment:24 of Trac #1520.  The overall goal is to simplify the
      kind-checking of typev-variable binders, and in particular to narrow
      the use of the "in-scope tyvar binder" stuff,
      which is needed only for associated types: see the new
      Note [Kind-checking tyvar binders for associated types] in TcHsType.
      
      Now
      
      * The "in-scope tyvar binder" stuff is done only in
           - kcLHsQTyVars, which is used for the LHsQTyVars of a
             data/newtype, or type family declaration.
      
           - tcFamTyPats, which is used for associated family instances;
             it now calls tcImplicitQTKBndrs, which in turn usese
             newFlexiKindedQTyVar
      
      * tcExpicitTKBndrs (which is used only for function signatures,
        data con signatures, pattern synonym signatures, and expression
        type signatures) now does not go via the "in-scope tyvar binder"
        stuff at all.
      
      While I'm still not happy with all this code, the code is generally
      simpler, and I think this is a useful step forward. It does cure
      the problem too.
      
      (It's hard to trigger the problem in vanilla Haskell code, because
      the renamer would normally use different names for nested binders,
      so I can't offer a test.)
      9fc40c73
  32. 21 Jun, 2018 1 commit
    • Ryan Scott's avatar
      Drop redundant Note · 50a35e59
      Ryan Scott authored
      Richard added a much better version of this Note in commit
      26e9806a, so I've decided to point
      to that instead.
      50a35e59