Implememt -fdefer-type-errors (Trac #5624)
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 12 Jan 2012 15:10:54 +0000 (15:10 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Thu, 12 Jan 2012 15:10:54 +0000 (15:10 +0000)
commit5508ada4b1d90ee54d92f69bbff7f66b3e8eceef
tree302bb0c73f96faf9249521b5baf0d879fe11fd6f
parentb8fe21e9ba5486256c83784ca8b9a839b5c527f4
Implememt -fdefer-type-errors (Trac #5624)

This patch implements the idea of deferring (most) type errors to
runtime, instead emitting only a warning at compile time.  The
basic idea is very simple:

 * The on-the-fly unifier in TcUnify never fails; instead if it
   gets stuck it emits a constraint.

 * The constraint solver tries to solve the constraints (and is
   entirely unchanged, hooray).

 * The remaining, unsolved constraints (if any) are passed to
   TcErrors.reportUnsolved.  With -fdefer-type-errors, instead of
   emitting an error message, TcErrors emits a warning, AND emits
   a binding for the constraint witness, binding it
   to (error "the error message"), via the new form of evidence
   TcEvidence.EvDelayedError.  So, when the program is run,
   when (and only when) that witness is needed, the program will
   crash with the exact same error message that would have been
   given at compile time.

Simple really.  But, needless to say, the exercise forced me
into some major refactoring.

 * TcErrors is almost entirely rewritten

 * EvVarX and WantedEvVar have gone away entirely

 * ErrUtils is changed a bit:
     * New Severity field in ErrMsg
     * Renamed the type Message to MsgDoc (this change
       touches a lot of files trivially)

 * One minor change is that in the constraint solver we try
   NOT to combine insoluble constraints, like Int~Bool, else
   all such type errors get combined together and result in
   only one error message!

 * I moved some definitions from TcSMonad to TcRnTypes,
   where they seem to belong more
45 files changed:
compiler/coreSyn/CoreLint.lhs
compiler/deSugar/DsBinds.lhs
compiler/deSugar/DsMonad.lhs
compiler/ghci/Linker.lhs
compiler/hsSyn/Convert.lhs
compiler/iface/LoadIface.lhs
compiler/iface/MkIface.lhs
compiler/iface/TcIface.lhs
compiler/main/CmdLineParser.hs
compiler/main/DynFlags.hs
compiler/main/ErrUtils.lhs
compiler/main/ErrUtils.lhs-boot
compiler/main/HeaderInfo.hs
compiler/main/HscMain.hs
compiler/main/HscTypes.lhs
compiler/main/Packages.lhs
compiler/parser/Lexer.x
compiler/rename/RnEnv.lhs
compiler/rename/RnNames.lhs
compiler/simplCore/CoreMonad.lhs
compiler/stgSyn/StgLint.lhs
compiler/typecheck/Inst.lhs
compiler/typecheck/TcBinds.lhs
compiler/typecheck/TcCanonical.lhs
compiler/typecheck/TcDeriv.lhs
compiler/typecheck/TcErrors.lhs
compiler/typecheck/TcEvidence.lhs
compiler/typecheck/TcExpr.lhs
compiler/typecheck/TcForeign.lhs
compiler/typecheck/TcHsSyn.lhs
compiler/typecheck/TcInteract.lhs
compiler/typecheck/TcMType.lhs
compiler/typecheck/TcMatches.lhs
compiler/typecheck/TcRnDriver.lhs
compiler/typecheck/TcRnMonad.lhs
compiler/typecheck/TcRnTypes.lhs
compiler/typecheck/TcSMonad.lhs
compiler/typecheck/TcSimplify.lhs
compiler/typecheck/TcSplice.lhs
compiler/typecheck/TcType.lhs
compiler/typecheck/TcUnify.lhs
compiler/types/InstEnv.lhs
compiler/types/Unify.lhs
docs/users_guide/flags.xml
docs/users_guide/using.xml