import Bag ( Bag, emptyBag, isEmptyBag, snocBag, foldBag )
import Id ( Id, idType )
import VarSet
-import DataCon ( DataCon, dataConArgTys, dataConType )
-import Const ( literalType, conType, Literal )
+import DataCon ( DataCon, dataConArgTys, dataConRepType )
+import PrimOp ( primOpType )
+import Literal ( literalType, Literal )
import Maybes ( catMaybes )
import Name ( isLocallyDefined, getSrcLoc )
import ErrUtils ( ErrMsg, Message, addErrLocHdrLine, pprBagOfErrors, dontAddErrLoc )
(a) *some* type errors
(b) locally-defined variables used but not defined
+
+Note: unless -dverbose-stg is on, display of lint errors will result
+in "panic: bOGUS_LVs".
+
+WARNING:
+~~~~~~~~
+
+This module has suffered bit-rot; it is likely to yield lint errors
+for Stg code that is currently perfectly acceptable for code
+generation. Solution: don't use it! (KSW 2000-05).
+
+
%************************************************************************
%* *
\subsection{``lint'' for various constructs}
\begin{code}
lintStgArg :: StgArg -> LintM (Maybe Type)
-lintStgArg (StgConArg con) = returnL (Just (conType con))
+lintStgArg (StgLitArg lit) = returnL (Just (literalType lit))
lintStgArg (StgVarArg v) = lintStgVar v
lintStgVar v = checkInScope v `thenL_`
Nothing -> returnL Nothing
Just arg_tys -> checkFunApp con_ty arg_tys (mkRhsConMsg con_ty arg_tys)
where
- con_ty = dataConType con
+ con_ty = dataConRepType con
\end{code}
\begin{code}
lintStgExpr :: StgExpr -> LintM (Maybe Type) -- Nothing if error found
+lintStgExpr (StgLit l) = returnL (Just (literalType l))
+
lintStgExpr e@(StgApp fun args)
= lintStgVar fun `thenMaybeL` \ fun_ty ->
mapMaybeL lintStgArg args `thenL` \ maybe_arg_tys ->
Nothing -> returnL Nothing
Just arg_tys -> checkFunApp fun_ty arg_tys (mkFunAppMsg fun_ty arg_tys e)
-lintStgExpr e@(StgCon con args _)
+lintStgExpr e@(StgConApp con args)
= mapMaybeL lintStgArg args `thenL` \ maybe_arg_tys ->
case maybe_arg_tys of
Nothing -> returnL Nothing
Just arg_tys -> checkFunApp con_ty arg_tys (mkFunAppMsg con_ty arg_tys e)
where
- con_ty = conType con
+ con_ty = dataConRepType con
+
+lintStgExpr e@(StgPrimApp op args _)
+ = mapMaybeL lintStgArg args `thenL` \ maybe_arg_tys ->
+ case maybe_arg_tys of
+ Nothing -> returnL Nothing
+ Just arg_tys -> checkFunApp op_ty arg_tys (mkFunAppMsg op_ty arg_tys e)
+ where
+ op_ty = primOpType op
lintStgExpr (StgLam _ bndrs _)
= addErrL (ptext SLIT("Unexpected StgLam") <+> ppr bndrs) `thenL_`
(trace (showSDoc (ppr e)) $
-- we only allow case of tail-call or primop.
(case scrut of
- StgApp _ _ -> returnL ()
- StgCon _ _ _ -> returnL ()
+ StgApp _ _ -> returnL ()
+ StgConApp _ _ -> returnL ()
other -> addErrL (mkCaseOfCaseMsg e)) `thenL_`
addInScopeVars [bndr] (lintStgAlts alts scrut_ty)
Just (tycon, tys_applied, cons) ->
let
arg_tys = dataConArgTys con tys_applied
+ -- This almost certainly does not work for existential constructors
in
checkL (con `elem` cons) (mkAlgAltMsg2 scrut_ty con) `thenL_`
checkL (length arg_tys == length args) (mkAlgAltMsg3 con args)