X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcEnv.lhs;h=1f9d3050eff2fd7094b829ee8ace3e4949b43511;hb=4c6a3f787abcaed009a574196d82237d9ae64fc8;hp=ac55f4b16df5e1c5b6a1062e3bbc4ef87c5cb512;hpb=f014b60bba8432be6f89c0dc99a54988fb4475af;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcEnv.lhs b/compiler/typecheck/TcEnv.lhs index ac55f4b..1f9d305 100644 --- a/compiler/typecheck/TcEnv.lhs +++ b/compiler/typecheck/TcEnv.lhs @@ -35,7 +35,6 @@ module TcEnv( tcLookupId, tcLookupTyVar, getScopedTyVarBinds, lclEnvElts, getInLocalScope, findGlobals, wrongThingErr, pprBinders, - refineEnvironment, tcExtendRecEnv, -- For knot-tying @@ -61,7 +60,6 @@ import IfaceEnv import TcRnMonad import TcMType import TcType -import TcGadt -- import TcSuspension import qualified Type import Var @@ -83,6 +81,7 @@ import HscTypes import SrcLoc import Outputable import Maybes +import FastString \end{code} @@ -135,10 +134,22 @@ tcLookupGlobal name tcLookupField :: Name -> TcM Id -- Returns the selector Id tcLookupField name = do - thing <- tcLookupGlobal name + thing <- tcLookup name -- Note [Record field lookup] case thing of - AnId id -> return id - other -> wrongThingErr "field name" (AGlobal thing) name + AGlobal (AnId id) -> return id + thing -> wrongThingErr "field name" thing name + +{- Note [Record field lookup] + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +You might think we should have tcLookupGlobal here, since record fields +are always top level. But consider + f = e { f = True } +Then the renamer (which does not keep track of what is a record selector +and what is not) will rename the definition thus + f_7 = e { f_7 = True } +Now the type checker will find f_7 in the *local* type environment, not +the global one. It's wrong, of course, but we want to report a tidy +error, not in TcEnv.notFound. -} tcLookupDataCon :: Name -> TcM DataCon tcLookupDataCon name = do @@ -452,38 +463,6 @@ find_thing ignore_it tidy_env (ATyVar tv ty) = do find_thing _ _ thing = pprPanic "find_thing" (ppr thing) \end{code} -\begin{code} -refineEnvironment - :: Refinement - -> Bool -- whether type equations are involved - -> TcM a - -> TcM a --- I don't think I have to refine the set of global type variables in scope --- Reason: the refinement never increases that set -refineEnvironment reft otherEquations thing_inside - | isEmptyRefinement reft -- Common case - , not otherEquations - = thing_inside - | otherwise - = do { env <- getLclEnv - ; let le' = mapNameEnv refine (tcl_env env) - ; setLclEnv (env {tcl_env = le'}) thing_inside } - where - refine elt@(ATcId { tct_co = Rigid co, tct_type = ty }) - | Just (co', ty') <- refineType reft ty - = elt { tct_co = Rigid (WpCo co' <.> co), tct_type = ty' } - refine elt@(ATcId { tct_co = Wobbly}) --- Main new idea: make wobbly things invisible whenever there --- is a refinement of any sort --- | otherEquations - = elt { tct_co = WobblyInvisible} - refine (ATyVar tv ty) - | Just (_, ty') <- refineType reft ty - = ATyVar tv ty' -- Ignore the coercion that refineType returns - - refine elt = elt -- Common case -\end{code} - %************************************************************************ %* * \subsection{The global tyvars}