summaryrefslogtreecommitdiff
path: root/compiler/coreSyn/CoreLint.lhs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-09-03 09:10:26 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2013-09-03 09:20:35 +0100
commitdfa8ef031c83998c163bb94fb84ff8e02ef86cf8 (patch)
tree419031d9a9985af5319a21f1cb0e7ef09a9c9249 /compiler/coreSyn/CoreLint.lhs
parente52554768ad28bd0c191826100786b1aee3295dc (diff)
downloadhaskell-dfa8ef031c83998c163bb94fb84ff8e02ef86cf8.tar.gz
Improve Linting in GHCi (fixes Trac #8215)
The original problem was that we weren't bringing varaibles bound in the interactive context into scope before Linting the result of a top-level declaration in GHCi. (We were doing this for expressions.) Moreover I found that we weren't Linting the result of desugaring a GHCi expression, which we really should be doing. It took me a bit of time to unravel all this, and I did some refactoring to make it easier next time. * CoreMonad contains the Lint wrappers that get the right environments into place. It always had endPass and lintPassResult (which Lints bindings), but now it has lintInteractiveExpr. * Both use a common function CoreMonad.interactiveInScope to find those in-scope variables. Quite a bit of knock-on effects from this, but nothing exciting.
Diffstat (limited to 'compiler/coreSyn/CoreLint.lhs')
-rw-r--r--compiler/coreSyn/CoreLint.lhs23
1 files changed, 18 insertions, 5 deletions
diff --git a/compiler/coreSyn/CoreLint.lhs b/compiler/coreSyn/CoreLint.lhs
index 68aaea5b5c..1913e3ab93 100644
--- a/compiler/coreSyn/CoreLint.lhs
+++ b/compiler/coreSyn/CoreLint.lhs
@@ -16,7 +16,7 @@ A ``lint'' pass to check for Core correctness
{-# OPTIONS_GHC -fprof-auto #-}
-module CoreLint ( lintCoreBindings, lintUnfolding ) where
+module CoreLint ( lintCoreBindings, lintUnfolding, lintExpr ) where
#include "HsVersions.h"
@@ -120,14 +120,15 @@ find an occurence of an Id, we fetch it from the in-scope set.
\begin{code}
-lintCoreBindings :: CoreProgram -> (Bag MsgDoc, Bag MsgDoc)
+lintCoreBindings :: [Var] -> CoreProgram -> (Bag MsgDoc, Bag MsgDoc)
-- Returns (warnings, errors)
-- If you edit this function, you may need to update the GHC formalism
-- See Note [GHC Formalism]
-lintCoreBindings binds
+lintCoreBindings local_in_scope binds
= initL $
- addLoc TopLevelBindings $
- addInScopeVars binders $
+ addLoc TopLevelBindings $
+ addInScopeVars local_in_scope $
+ addInScopeVars binders $
-- Put all the top-level binders in scope at the start
-- This is because transformation rules can bring something
-- into use 'unexpectedly'
@@ -178,6 +179,18 @@ lintUnfolding locn vars expr
(_warns, errs) = initL (addLoc (ImportedUnfolding locn) $
addInScopeVars vars $
lintCoreExpr expr)
+
+lintExpr :: [Var] -- Treat these as in scope
+ -> CoreExpr
+ -> Maybe MsgDoc -- Nothing => OK
+
+lintExpr vars expr
+ | isEmptyBag errs = Nothing
+ | otherwise = Just (pprMessageBag errs)
+ where
+ (_warns, errs) = initL (addLoc TopLevelBindings $
+ addInScopeVars vars $
+ lintCoreExpr expr)
\end{code}
%************************************************************************