1. 07 Aug, 2015 1 commit
  2. 05 Aug, 2015 1 commit
    • Simon Peyton Jones's avatar
      Tidy up and refactor wildcard handling · 95364812
      Simon Peyton Jones authored
      When examining #10615, I found the wildcard handling hard
      to understand.  This patch refactors quite a bit, but with
      no real change in behaviour.
      
       * Split out TcIdSigInfo from TcSigInfo, as a separate type,
         like TcPatSynInfo.
      
       * Make TcIdSigInfo express more invariants by pushing the
         wildard info into TcIdSigBndr
      
       * Remove all special treatment of unification variables that arise
         from wildcards; so the TauTv of TcType.MetaInfo loses its Bool
         argument.
      
      A ton of konck on changes.  The result is significantly simpler, I think.
      95364812
  3. 15 Jul, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Fix #10642. · 9f978b67
      eir@cis.upenn.edu authored
      Representational equalities cannot discharge nominal ones.
      Even if, somehow, this didn't cause a type error (as reported
      in the ticket), it would surely cause a core lint error.
      9f978b67
  4. 06 Jul, 2015 1 commit
  5. 26 Jun, 2015 1 commit
    • Simon Peyton Jones's avatar
      Treat out-of-scope variables as holes · fb7b6922
      Simon Peyton Jones authored
      This patch implements the idea in Trac #10569.
      
      * An out-of-scope variable is treated as a typed expression
        hole.
      
      * That is, we don't report it in the type checker, not the
        renamer, and we when we do report it, we give its type.
      
      * Moreover, we can defer the error to runtime with
        -fdefer-typed-holes
      
      In implementation terms:
      
      * The renamer turns an unbound variable into a HsUnboundVar
      
      * The type checker emits a Hole constraint for a
        HsUnboundVar, and turns it back into a HsVar
      
      It was a bit painful to implement because a whole raft of
      error messages change slightly.  But there was absolutely
      nothing hard in principle.
      
      Holes are reported with a bunch of possibly-useful context,
      notably the "relevant bindings".  I found that this was
      distracting clutter in the very common case of a mis-typed
      variable that is only accidentally not in scope, so I've
      arranged to print the context information only for true holes,
      that is ones starting with an underscore.
      
      Unbound data constructors use in patterns, like
        f (D x) = x
      are still reportd by the renamer, and abort compilation
      before type checking.
      fb7b6922
  6. 21 Jun, 2015 1 commit
  7. 18 Jun, 2015 2 commits
  8. 16 Jun, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Decompose wanted repr. eqs. when no matchable givens. · ff82387d
      eir@cis.upenn.edu authored
      This is pursuant to a conversion with SPJ, where we agreed that
      the logic behind Note [Instance and Given overlap] in TcInteract
      applied to newtype decomposition for representational equality.
      
      There is no bug report or test case, as tickling this kind of thing
      is quite hard to do!
      ff82387d
  9. 15 Jun, 2015 1 commit
  10. 11 Jun, 2015 1 commit
    • Simon Peyton Jones's avatar
      Another major improvement of "improvement" · ddbb97d0
      Simon Peyton Jones authored
      I wasn't very happy with my fix to Trac #10009. This is much better.
      
      The main idea is that the inert set now contains a "model", which
      embodies *all* the (nominal) equalities that we know about, with
      a view to exposing unifications.  This requires a lot fewer iterations
      of the solver than before.
      
      There are extensive comments in
       TcSMonad:  Note [inert_model: the inert model]
                  Note [Adding an inert canonical constraint the InertCans]
      
      The big changes are
      
        * New inert_model field in InertCans
      
        * Functions addInertEq, addInertCan deal with adding a
          constraint, maintaining the model
      
        * A nice improvement is that unification variables can
          unify with fmvs, so that from, say   alpha ~ fmv
          we get              alpha := fmv
          See Note [Orientation of equalities with fmvs] in TcFlatten
          It's still not perfect, as the Note explains
      
      New flag -fconstraint-solver-iterations=n, allows us to control
      the number of constraint solver iterations, and in particular
      will flag up when it's more than a small number.
      
      Performance is generally slightly better:
      T5837 is a lot better for some reason.
      ddbb97d0
  11. 01 Jun, 2015 1 commit
  12. 12 May, 2015 1 commit
    • David Terei's avatar
      New handling of overlapping inst in Safe Haskell · 4fffbc34
      David Terei authored
      We do much better now due to the newish per-instance flags. Rather than
      mark any module that uses `-XOverlappingInstances`,
      `-XIncoherentInstances` or the new `OVERLAP*` pragmas as unsafe, we
      regard them all as safe and defer the check until an overlap occurs.
      
      An type-class method call that involves overlapping instances is
      considered _unsafe_ when:
      
      1) The most specific instance, Ix, is from a module marked `-XSafe`
      2) Ix is an orphan instance or a MPTC
      3) At least one instance that Ix overlaps, Iy, is:
         a) from a different module than Ix
         AND
         b) Iy is not marked `OVERLAPPABLE`
      
      This check is only enforced in modules compiled with `-XSafe` or
      `-XTrustworthy`.
      
      This fixes Safe Haskell to work with the latest overlapping instance
      pragmas, and also brings consistent behavior. Previously, Safe Inferred
      modules behaved differently than `-XSafe` modules.
      4fffbc34
  13. 30 Apr, 2015 1 commit
  14. 29 Apr, 2015 1 commit
    • Simon Peyton Jones's avatar
      Improve improvement in the constraint solver · a1275a76
      Simon Peyton Jones authored
      This regrettably-big patch substantially improves the way in which
      "improvement" happens in the constraint solver.  It was triggered by
      trying to crack Trac #10009, but it turned out to solve #10340 as
      well.
      
      The big picture, with several of the trickiest examples, is described
      in Note [The improvement story] in TcInteract.
      
      The major change is this:
      
      * After solving we explicitly try "improvement", by
           - making the unsolved Wanteds into Deriveds
           - allowing Deriveds to rewrite Deriveds
        This more aggressive rewriting "unlocks" some extra
        guess-free unifications.
      
      * The main loop is in TcInteract.solveSimpleWanteds, but I also ended
        up refactoring TcSimplify.simpl_loop, and its surrounding code.
      
        Notably, any insolubles from the Givens are pulled out
        and treated separately, rather than staying in the inert set
        during the solveSimpleWanteds loop.
      
      There are a lot of follow-on changes
      
      * Do not emit generate Derived improvements from Wanteds.
        This saves work in the common case where they aren't needed.
      
      * For improvement we should really do type-class reduction on Derived
        constraints in doTopReactDict.  That entailed changing the GenInst
        constructor a bit; a local and minor change
      
      * Some annoying faffing about with dropping derived constraints;
        see dropDerivedWC, dropDerivedSimples, dropDerivedInsols,
        and their Notes.
      
      * Some substantial refactoring in TcErrors.reportWanteds.
        This work wasn't strictly forced, but I got sucked into it.
        All the changes are in TcErrors.
      
      * Use TcS.unifyTyVar consistently, rather than setWantedTyBind,
        so that unifications are properly tracked.
      
      * Refactoring around solveWantedsTcM, solveWantedsAndDrop.
        They previously guaranteed a zonked result, but it's more
        straightforward for clients to zonk.
      a1275a76
  15. 09 Apr, 2015 1 commit
  16. 23 Mar, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Do proper depth checking in the flattener to avoid looping. · c1edbdfd
      eir@cis.upenn.edu authored
      This implements (roughly) the plan put forward in comment:14:ticket:7788,
      fixing #7788, #8550, #9554, #10139, and addressing concerns raised in #10079.
      There are some regressions w.r.t. GHC 7.8, but only with pathological type
      families (like F a = F a). This also (hopefully -- don't have a test case)
      fixes #10158. Unsolved problems include #10184 and #10185, which are both
      known deficiencies of the approach used here.
      
      As part of this change, the plumbing around detecting infinite loops has
      changed. Instead of -fcontext-stack and -ftype-function-depth, we now have
      one combined -freduction-depth parameter. Setting it to 0 disbales the
      check, which is now the recommended way to get (terminating) code to
      typecheck in releases. (The number of reduction steps may well change between
      minor GHC releases!)
      
      This commit also introduces a new IntWithInf type in BasicTypes
      that represents an integer+infinity. This type is used in a few
      places throughout the code.
      
      Tests in
        indexed-types/should_fail/T7788
        indexed-types/should_fail/T8550
        indexed-types/should_fail/T9554
        indexed-types/should_compile/T10079
        indexed-types/should_compile/T10139
        typecheck/should_compile/T10184  (expected broken)
        typecheck/should_compile/T10185  (expected broken)
      
      This commit also changes performance testsuite numbers, for the better.
      c1edbdfd
  17. 09 Jan, 2015 1 commit
  18. 08 Jan, 2015 1 commit
    • Edward Z. Yang's avatar
      Add 'DeBruijn' constructor, which generalizes "key modulo alpha-renaming." · ccef0146
      Edward Z. Yang authored
      
      
      Summary:
      We need equality over Types, etc; and this equality has to be modulo alpha
      renaming. Previously, we baked CmEnv into the generic "empty, singleton, many"
      structure. This isn't great, really GenMap should be more generic than that.
      
      The insight: we've defined the key wrong: the key should be *equipped*
      with the alpha-renaming information (CmEnv) and a TrieMap queried with this.
      This is what the DeBruijn constructor does.
      
      Now, when we define TrieMap instances, we don't have to synthesize an emptyCME
      to pass to the helper functions: we have all the information we need. To make a
      recursive call, we construct a new DeBruijn with the updated CME and then
      call lookupTM on that. We can even define a plain old Eq instance on DeBruijn
      respecting alpha-renaming.  There are number of other good knock-on effects.
      
      This patch does add a bit of boxing and unboxing, but nothing the optimizer
      shouldn't be able to eliminate.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: simonpj, austin
      
      Subscribers: carter, thomie
      
      Differential Revision: https://phabricator.haskell.org/D608
      
      GHC Trac Issues: #9960
      ccef0146
  19. 06 Jan, 2015 1 commit
    • Simon Peyton Jones's avatar
      Major patch to add -fwarn-redundant-constraints · 32973bf3
      Simon Peyton Jones authored
      The idea was promted by Trac #9939, but it was Christmas, so I did
      some recreational programming that went much further.
      
      The idea is to warn when a constraint in a user-supplied context is
      redundant.  Everything is described in detail in
        Note [Tracking redundant constraints]
      in TcSimplify.
      
      Main changes:
      
       * The new ic_status field in an implication, of type ImplicStatus.
         It replaces ic_insol, and includes information about redundant
         constraints.
      
       * New function TcSimplify.setImplicationStatus sets the ic_status.
      
       * TcSigInfo has sig_report_redundant field to say whenther a
         redundant constraint should be reported; and similarly
         the FunSigCtxt constructor of UserTypeCtxt
      
       * EvBinds has a field eb_is_given, to record whether it is a given
         or wanted binding. Some consequential chagnes to creating an evidence
         binding (so that we record whether it is given or wanted).
      
       * AbsBinds field abs_ev_binds is now a *list* of TcEvBiinds;
         see Note [Typechecking plan for instance declarations] in
         TcInstDcls
      
       * Some significant changes to the type checking of instance
         declarations; Note [Typechecking plan for instance declarations]
         in TcInstDcls.
      
       * I found that TcErrors.relevantBindings was failing to zonk the
         origin of the constraint it was looking at, and hence failing to
         find some relevant bindings.  Easy to fix, and orthogonal to
         everything else, but hard to disentangle.
      
      Some minor refactorig:
      
       * TcMType.newSimpleWanteds moves to Inst, renamed as newWanteds
      
       * TcClassDcl and TcInstDcls now have their own code for typechecking
         a method body, rather than sharing a single function. The shared
         function (ws TcClassDcl.tcInstanceMethodBody) didn't have much code
         and the differences were growing confusing.
      
       * Add new function TcRnMonad.pushLevelAndCaptureConstraints, and
         use it
      
       * Add new function Bag.catBagMaybes, and use it in TcSimplify
      32973bf3
  20. 31 Dec, 2014 2 commits
    • Simon Peyton Jones's avatar
      When solving one Given from another, use the depth to control which way round · d8d00318
      Simon Peyton Jones authored
      See Note [Replacement vs keeping].
      
      There's a bit further to go with this change (to report unused givens).
      But it's already an improvement; see the latent bug described in the Note.
      d8d00318
    • Simon Peyton Jones's avatar
      Eliminate the final two calls to xCtEvidence · fd97d2a7
      Simon Peyton Jones authored
      I always found calls to TcCanonical.xCtEvidence hard to grok; and I
      found that we only had two left. This patch eliminates them, along
      with xCtEvidence, its accompanying comments, and the auxiliary
      XEvTerm type.
      
      The two remaining calls were these:
      
       * One was in newSCWorkFromFlavored, where we'd already done
         case-splitting for given/wanted/derived.  So inlining the xCtEvidence
         made the code simpler, clearer, and faster.
      
       * The other was in canTuple; here all of xCtEvidence's functionality
         was needed, but inlining again made a net gain in code size and
         clarity.
      fd97d2a7
  21. 30 Dec, 2014 1 commit
  22. 23 Dec, 2014 1 commit
    • Simon Peyton Jones's avatar
      Eliminate so-called "silent superclass parameters" · a6f0f5ab
      Simon Peyton Jones authored
      The purpose of silent superclass parameters was to solve the
      awkward problem of superclass dictinaries being bound to bottom.
      See THE PROBLEM in Note [Recursive superclasses] in TcInstDcls
      
      Although the silent-superclass idea worked,
      
        * It had non-local consequences, and had effects even in Haddock,
          where we had to discard silent parameters before displaying
          instance declarations
      
        * It had unexpected peformance costs, shown up by Trac #3064 and its
          test case.  In monad-transformer code, when constructing a Monad
          dictionary you had to pass an Applicative dictionary; and to
          construct that you neede a Functor dictionary. Yet these extra
          dictionaries were often never used.  (All this got much worse when
          we added Applicative as a superclass of Monad.) Test T3064
          compiled *far* faster after silent superclasses were eliminated.
      
        * It introduced new bugs.  For example SilentParametersOverlapping,
          T5051, and T7862, all failed to compile because of instance overlap
          directly because of the silent-superclass trick.
      
      So this patch takes a new approach, which I worked out with Dimitrios
      in the closing hours before Christmas.  It is described in detail
      in THE PROBLEM in Note [Recursive superclasses] in TcInstDcls.
      
      Seems to work great!
      
      Quite a bit of knock-on effect
      
       * The main implementation work is in tcSuperClasses in TcInstDcls
         Everything else is fall-out
      
       * IdInfo.DFunId no longer needs its n-silent argument
         * Ditto IDFunId in IfaceSyn
         * Hence interface file format changes
      
       * Now that DFunIds do not have silent superclass parameters, printing
         out instance declarations is simpler. There is tiny knock-on effect
         in Haddock, so that submodule is updated
      
       * I realised that when computing the "size of a dictionary type"
         in TcValidity.sizePred, we should be rather conservative about
         type functions, which can arbitrarily increase the size of a type.
         Hence the new datatype TypeSize, which has a TSBig constructor for
         "arbitrarily big".
      
       * instDFunType moves from TcSMonad to Inst
      
       * Interestingly, CmmNode and CmmExpr both now need a non-silent
         (Ord r) in a couple of instance declarations. These were previously
         silent but must now be explicit.
      
       * Quite a bit of wibbling in error messages
      a6f0f5ab
  23. 18 Dec, 2014 1 commit
    • Adam Gundry's avatar
      Amend TcPluginM interface · 726ea08a
      Adam Gundry authored
      Summary:
      Expose some new functions in TcPluginM and remove one, in the light of
      experience writing plugins.  In particular, I've removed lookupRdrName
      because using it to import modules containing instances leads to subtle
      bugs; I've expanded on the lookupRdrNameInModuleForPlugins comments.
      
      Test Plan: validate
      
      Reviewers: simonpj, austin
      
      Reviewed By: austin
      
      Subscribers: goldfire, ezyang, carter, thomie, yav, gridaphobe
      
      Differential Revision: https://phabricator.haskell.org/D553
      
      Conflicts:
      	compiler/typecheck/TcSMonad.hs
      726ea08a
  24. 12 Dec, 2014 2 commits
    • eir@cis.upenn.edu's avatar
      Flat constraint --> Simple constraint · 8a0de692
      eir@cis.upenn.edu authored
      8a0de692
    • eir@cis.upenn.edu's avatar
      Rewrite `Coercible` solver · 0cc47eb9
      eir@cis.upenn.edu authored
      Summary:
      This is a rewrite of the algorithm to solve for Coercible "instances".
      
      A preliminary form of these ideas is at
      https://ghc.haskell.org/trac/ghc/wiki/Design/NewCoercibleSolver
      
      The basic idea here is that the `EqPred` constructor of `PredTree`
      now is parameterised by a new type `EqRel` (where
      `data EqRel = NomEq | ReprEq`). Thus, every equality constraint can
      now talk about nominal equality (the usual case) or representational
      equality (the `Coercible` case).
      
      This is a change from the previous
      behavior where `Coercible` was just considered a regular class with
      a special case in `matchClassInst`.
      
      Because of this change, representational equalities are now
      canonicalized just like nominal ones, allowing more equalities
      to be solved -- in particular, the case at the top of #9117.
      
      A knock-on effect is that the flattener must be aware of the
      choice of equality relation, because the inert set now stores
      both representational inert equalities alongside the nominal
      inert equalities. Of course, we can use representational equalities
      to rewrite only within another representational equality --
      thus the parameterization of the flattener.
      
      A nice side effect of this change is that I've introduced a new
      type `CtFlavour`, which tracks G vs. W vs. D, removing some ugliness
      in the flattener.
      
      This commit includes some refactoring as discussed on D546.
      It also removes the ability of Deriveds to rewrite Deriveds.
      
      This fixes bugs #9117 and #8984.
      
      Reviewers: simonpj, austin, nomeata
      
      Subscribers: carter, thomie
      
      Differential Revision: https://phabricator.haskell.org/D546
      
      GHC Trac Issues: #9117, #8984
      0cc47eb9
  25. 10 Dec, 2014 3 commits
    • Simon Peyton Jones's avatar
      Implement a fast path for new constraints looking like (a~b), namely unifyWanted · 832f8db2
      Simon Peyton Jones authored
      Looking at some typechecker traces I could see places where we were laboriously
      creating a Refl coercion.  This patch short-circuits the process.
      
      See TcCanonical:
        Note [unifyWanted and unifyDerived]
        Note [Decomposing TyConApps]
      
      I ended up with some refactoring, notably
      
        * I moved xCtEvidence, rewriteEvidence, rewriteEqEvidence
          from TcSMonad to TcCanonical
      
      There are some knock-on effects, but only minor ones.
      832f8db2
    • Simon Peyton Jones's avatar
      When flattening, try reducing type-family applications eagerly · bcb967ab
      Simon Peyton Jones authored
      This short-cut can improve performance quite a bit, by short-circuiting
      the process of creating a fresh constraint and binding for each reduction.
      
      See Note [Reduce type family applications eagerly] in TcFlatten
      
      To do this I had to generalise the inert_flat_cache a bit, so that the
      rhs is not necessarily a type variable; but nothing fundamental.
      bcb967ab
    • Simon Peyton Jones's avatar
      Reorganise the work list, so that flattening goals are treated in the right order · 13b0b460
      Simon Peyton Jones authored
      Trac #9872 showed the importance of processing goals in depth-first, so that
      we do not build up a huge pool of suspended function calls, waiting for their
      children to fire.  There is a detailed explanation in
           Note [The flattening work list]
      in TcFlatten
      
      The effect for Trac #9872 (slow1.hs) is dramatic.  We go from too long
      to wait down to 28Gbyte allocation.  GHC 7.8.3 did 116Gbyte allocation!
      13b0b460
  26. 08 Dec, 2014 2 commits
  27. 03 Dec, 2014 1 commit
  28. 02 Dec, 2014 1 commit
    • Simon Peyton Jones's avatar
      Rename Untouchables to TcLevel · 26a3d0fe
      Simon Peyton Jones authored
      This is a long-overdue renaming
         Untouchables  -->   TcLevel
      It is renaming only; no change in functionality.
      
      We really wanted to get this done before the 7.10 fork.
      26a3d0fe
  29. 30 Nov, 2014 1 commit
    • Edward Z. Yang's avatar
      Filter instance visibility based on set of visible orphans, fixes #2182. · 4c834fdd
      Edward Z. Yang authored
      
      
      Summary:
      Amazingly, the fix for this very old bug is quite simple: when type-checking,
      maintain a set of "visible orphan modules" based on the orphans list of
      modules which we explicitly imported.  When we import an instance and it
      is an orphan, we check if it is in the visible modules set, and if not,
      ignore it.  A little bit of refactoring for when orphan-hood is calculated
      happens so that we always know if an instance is an orphan or not.
      
      For GHCi, we preinitialize the visible modules set based on the list of
      interactive imports which are active.
      
      Future work: Cache the visible orphan modules set for GHCi, rather than
      recomputing it every type-checking round.  (But it's tricky what to do when you
      /remove/ a module: you need a data structure a little more complicated than
      just a set of modules.)
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: new tests and validate
      
      Reviewers: simonpj, austin
      
      Subscribers: thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D488
      
      GHC Trac Issues: #2182
      4c834fdd
  30. 28 Nov, 2014 2 commits
  31. 21 Nov, 2014 1 commit
  32. 20 Nov, 2014 2 commits
    • Jan Stolarek's avatar
      Split SynTyCon to SynonymTyCon and FamilyTyCon · 696fc4ba
      Jan Stolarek authored
      This patch refactors internal representation of type synonyms and type families by splitting them into two separate data constructors of TyCon data type. The main motivation is is that some fields make sense only for type synonyms and some make sense only for type families. This will be even more true with the upcoming injective type families.
      
      There is also some refactoring of names to keep the naming constistent. And thus tc_kind field has become tyConKind and tc_roles has become tcRoles. Both changes are not visible from the outside of TyCon module.
      
      Updates haddock submodule
      
      Reviewers: simonpj
      
      Differential Revision: https://phabricator.haskell.org/D508
      
      GHC Trac Issues: #9812
      696fc4ba
    • Adam Gundry's avatar
      Implement typechecker plugins · 64cb4968
      Adam Gundry authored
      Summary:
      See https://ghc.haskell.org/trac/ghc/wiki/Plugins/TypeChecker
      
      This is based on work by Iavor Diatchki and Eric Seidel.
      
      Test Plan: validate
      
      Reviewers: simonpj, austin
      
      Reviewed By: austin
      
      Subscribers: gridaphobe, yav, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D489
      
      Conflicts:
      	docs/users_guide/7.10.1-notes.xml
      64cb4968