Merge remote branch 'origin/master' Fixed conflicts in: compiler/typecheck/TcCanonical.lhs compiler/typecheck/TcErrors.lhs compiler/typecheck/TcInteract.lhs
Introducing: 1) Postponing the application of instances when there is a possibility of a given matching. With the addition of prioritizing equalities this fixes #5002 and #4981. 2) Implemented caching of flattening in constraint simplification. This improves efficiency (fixes #5030) 3) Simplified pushing of unsolved wanteds (now pushing only equalities) inside implications.
Merge remote branch 'origin/master' into ghc-new-co Conflicts: compiler/typecheck/TcErrors.lhs compiler/typecheck/TcSMonad.lhs compiler/typecheck/TcType.lhs compiler/types/TypeRep.lhs
Tidy up SigTv This just a refactoring, removing dead code
Fix Trac #5130: missed error report Some out of date code in TcErrors was suppressing an error report -- so some type-incorrect code leaked out and confused a later bit of the compiler.
This BIG PATCH contains most of the work for the New Coercion Representation See the paper "Practical aspects of evidence based compilation in System FC" * Coercion becomes a data type, distinct from Type * Coercions become value-level things, rather than type-level things, (although the value is zero bits wide, like the State token) A consequence is that a coerion abstraction increases the arity by 1 (just like a dictionary abstraction) * There is a new constructor in CoreExpr, namely Coercion, to inject coercions into terms
Major refactoring of the type inference engine This patch embodies many, many changes to the contraint solver, which make it simpler, more robust, and more beautiful. But it has taken me ages to get right. The forcing issue was some obscure programs involving recursive dictionaries, but these eventually led to a massive refactoring sweep. Main changes are: * No more "frozen errors" in the monad. Instead "insoluble constraints" are now part of the WantedConstraints type. * The WantedConstraint type is a product of bags, instead of (as before) a bag of sums. This eliminates a good deal of tagging and untagging. * This same WantedConstraints data type is used - As the way that constraints are gathered - As a field of an implication constraint - As both argument and result of solveWanted - As the argument to reportUnsolved * We do not generate any evidence for Derived constraints. They are purely there to allow "impovement" by unifying unification variables. * In consequence, nothing is ever *rewritten* by a Derived constraint. This removes, by construction, all the horrible potential recursive-dictionary loops that were making us tear our hair out. No more isGoodRecEv search either. Hurrah! * We add the superclass Derived constraints during canonicalisation, after checking for duplicates. So fewer superclass constraints are generated than before. * Skolem tc-tyvars no longer carry SkolemInfo. Instead, the SkolemInfo lives in the GivenLoc of the Implication, where it can be tidied, zonked, and substituted nicely. This alone is a major improvement. * Tidying is improved, so that we tend to get t1, t2, t3, rather than t1, t11, t111, etc Moreover, unification variables are always printed with a digit (thus a0, a1, etc), so that plain 'a' is available for a skolem arising from a type signature etc. In this way, (a) We quietly say which variables are unification variables, for those who know and care (b) Types tend to get printed as the user expects. If he writes f :: a -> a f = ...blah... then types involving 'a' get printed with 'a', rather than some tidied variant. * There are significant improvements in error messages, notably in the "Cannot deduce X from Y" messages.
Fix recursive superclasses (again). Fixes Trac #4809. This patch finally deals with the super-delicate question of superclases in possibly-recursive dictionaries. The key idea is the DFun Superclass Invariant (see TcInstDcls): In the body of a DFun, every superclass argument to the returned dictionary is either * one of the arguments of the DFun, or * constant, bound at top level To establish the invariant, we add new "silent" superclass argument(s) to each dfun, so that the dfun does not do superclass selection internally. There's a bit of hoo-ha to make sure that we don't print those silent arguments in error messages; a knock on effect was a change in interface-file format. A second change is that instead of the complex and fragile "self dictionary binding" in TcInstDcls and TcClassDcl, using the same mechanism for existential pattern bindings. See Note [Subtle interaction of recursion and overlap] in TcInstDcls and Note [Binding when looking up instances] in InstEnv. Main notes are here: * Note [Silent Superclass Arguments] in TcInstDcls, including the DFun Superclass Invariant Main code changes are: * The code for MkId.mkDictFunId and mkDictFunTy * DFunUnfoldings get a little more complicated; their arguments are a new type DFunArg (in CoreSyn) * No "self" argument in tcInstanceMethod * No special tcSimplifySuperClasss * No "dependents" argument to EvDFunApp IMPORTANT It turns out that it's quite tricky to generate the right DFunUnfolding for a specialised dfun, when you use SPECIALISE INSTANCE. For now I've just commented it out (in DsBinds) but that'll lose some optimisation, and I need to get back to this.
Improve error message on advice from a user See Trac #4499
Ensure that instance overlap errors are report properly This (annoyingly) requires us to re-flatten the class predicate. See Note [Flattening in error message generation]
A (final) re-engineering of the new typechecker Regression testing and user feedback for GHC 7.0 taught us a lot. This patch fixes numerous small bugs, and some major ones (eg Trac #4484, #4492), and improves type error messages. The main changes are: * Entirely remove the "skolem equivalance class" stuff; a very useful simplification * Instead, when flattening "wanted" constraints we generate unification variables (not flatten-skolems) for the flattened type function application * We then need a fixup pass at the end, TcSimplify.solveCTyFunEqs, which resolves any residual equalities of form F xi ~ alpha * When we come across a definite failure (e.g. Int ~ [a]), we now defer reporting the error until the end, in case we learn more about 'a'. That is particularly important for occurs-check errors. These are called "frozen" type errors. * Other improvements in error message generation. * Better tracing messages
Improve error messages In particular, instead of Cannot match 'a' with 'b' we get Could not deduce (a~b) from context (F a ~ b) or whatever
Tidy up RuntimeUnkSkols a bit more
Fix debugger A bit yukky; see Note [Runtime skolems] in TcErrors. But it works, and the debugger just is yukky in places.
Major pass through type checker:(1) prioritizing equalities, (2) improved Derived mechanism, (3) bugfixes
Suppress ambiguity errors if any other errors occur
Suppress knock-on typechecker errors The error cascade caused puzzling errors in T4093b, and suppressing some seems like a good plan. Very few test outputs change.
Some refactoring and simplification in TcInteract.occurCheck
Further improvements in error messages
Add separate functions for querying DynFlag and ExtensionFlag options and remove the temporary DOpt class workaround.