See Note [WildCard binders] in SimplEnv. Spotted by Roman.
= do { checkL (not (var == oneTupleDataConId))
(ptext (sLit "Illegal one-tuple"))
- ; checkDeadIdOcc var
+ ; checkL (not (var `hasKey` wildCardKey))
+ (ptext (sLit "Occurence of a wild-card binder") <+> ppr var)
+ -- See Note [WildCard binders] in SimplEnv
+
+ ; checkDeadIdOcc var
; var' <- lookupIdInScope var
; return (idType var') }
import Outputable
import FastString
import UniqSupply
-import Unique ( mkBuiltinUnique )
import BasicTypes
import Util ( notNull, zipEqual )
import Constants
-- that you expect to use only at a *binding* site. Do not use it at
-- occurrence sites because it has a single, fixed unique, and it's very
-- easy to get into difficulties with shadowing. That's why it is used so little.
+-- See Note [WildCard binders] in SimplEnv
mkWildValBinder :: Type -> Id
-mkWildValBinder ty = mkSysLocal (fsLit "wild") (mkBuiltinUnique 1) ty
+mkWildValBinder ty = mkLocalId wildCardName ty
mkWildCase :: CoreExpr -> Type -> Type -> [CoreAlt] -> CoreExpr
-- Make a case expression whose case binder is unused
mkTupleTyConUnique
)
import BasicTypes ( Boxity(..), Arity )
-import Name ( Name, mkInternalName, mkExternalName )
+import Name ( Name, mkInternalName, mkExternalName, mkSystemVarName )
import SrcLoc
import FastString
\end{code}
\begin{code}
+wildCardName :: Name
+wildCardName = mkSystemVarName wildCardKey (fsLit "wild")
+
runMainIOName :: Name
runMainIOName = varQual gHC_TOP_HANDLER (fsLit "runMainIO") runMainKey
noMethodBindingErrorIdKey, nonExhaustiveGuardsErrorIdKey,
runtimeErrorIdKey, parErrorIdKey, parIdKey, patErrorIdKey,
realWorldPrimIdKey, recConErrorIdKey, recUpdErrorIdKey,
- traceIdKey,
+ traceIdKey, wildCardKey,
unpackCStringUtf8IdKey, unpackCStringAppendIdKey,
unpackCStringFoldrIdKey, unpackCStringIdKey :: Unique
-absentErrorIdKey = mkPreludeMiscIdUnique 1
+wildCardKey = mkPreludeMiscIdUnique 0 -- See Note [WildCard]
+absentErrorIdKey = mkPreludeMiscIdUnique 1
augmentIdKey = mkPreludeMiscIdUnique 3
appendIdKey = mkPreludeMiscIdUnique 4
buildIdKey = mkPreludeMiscIdUnique 5
import VarSet
import OrdList
import Id
+import MkCore
+import TysWiredIn
import qualified CoreSubst
import qualified Type ( substTy, substTyVarBndr, substTyVar )
import Type hiding ( substTy, substTyVarBndr, substTyVar )
\begin{code}
mkSimplEnv :: SimplifierMode -> SimplEnv
mkSimplEnv mode
- = SimplEnv { seCC = subsumedCCS,
- seMode = mode, seInScope = emptyInScopeSet,
- seFloats = emptyFloats,
- seTvSubst = emptyVarEnv, seIdSubst = emptyVarEnv }
+ = SimplEnv { seCC = subsumedCCS
+ , seMode = mode
+ , seInScope = init_in_scope
+ , seFloats = emptyFloats
+ , seTvSubst = emptyVarEnv
+ , seIdSubst = emptyVarEnv }
-- The top level "enclosing CC" is "SUBSUMED".
----------------------
+init_in_scope :: InScopeSet
+init_in_scope = mkInScopeSet (unitVarSet (mkWildValBinder unitTy))
+ -- See Note [WildCard binders]
+\end{code}
+
+Note [WildCard binders]
+~~~~~~~~~~~~~~~~~~~~~~~
+The program to be simplified may have wild binders
+ case e of wild { p -> ... }
+We want to *rename* them away, so that there are no
+occurrences of 'wild' (with wildCardKey). The easy
+way to do that is to start of with a representative
+Id in the in-scope set
+
+There should be no *occurrences* of wild.
+
+\begin{code}
getMode :: SimplEnv -> SimplifierMode
getMode env = seMode env