Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
5a30ed40
Commit
5a30ed40
authored
27 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1997-05-18 23:09:49 by sof]
new PP
parent
9d4d03d5
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/compiler/stgSyn/StgLint.lhs
+47
-46
47 additions, 46 deletions
ghc/compiler/stgSyn/StgLint.lhs
with
47 additions
and
46 deletions
ghc/compiler/stgSyn/StgLint.lhs
+
47
−
46
View file @
5a30ed40
...
...
@@ -12,23 +12,24 @@ IMP_Ubiq(){-uitous-}
import StgSyn
import Bag ( emptyBag, isEmptyBag, snocBag, foldBag )
import Bag (
Bag,
emptyBag, isEmptyBag, snocBag, foldBag )
import Id ( idType, isDataCon, dataConArgTys,
emptyIdSet, isEmptyIdSet, elementOfIdSet,
mkIdSet, intersectIdSets,
unionIdSets, idSetToList, SYN_IE(IdSet),
GenId{-instanced NamedThing-}
GenId{-instanced NamedThing-}
, SYN_IE(Id)
)
import Literal ( literalType, Literal{-instance Outputable-} )
import Maybes ( catMaybes )
import Name ( isLocallyDefined, getSrcLoc )
import Outputable ( Outputable(..){-instance * []-} )
import PprType ( GenType{-instance Outputable-}, TyCon )
import PprStyle ( PprStyle )
import Pretty -- quite a bit of it
import PrimOp ( primOpType )
import SrcLoc ( SrcLoc{-instance Outputable-} )
import Type ( mkFunTys, splitFunTy, maybeAppDataTyConExpandingDicts,
isTyVarTy, eqTy, splitFunTyExpandingDicts
isTyVarTy, eqTy, splitFunTyExpandingDicts
, SYN_IE(Type)
)
import Util ( zipEqual, pprPanic, panic, panic# )
...
...
@@ -56,12 +57,12 @@ lintStgBindings sty whodunnit binds
= _scc_ "StgLint"
case (initL (lint_binds binds)) of
Nothing -> binds
Just msg -> pprPanic "" (
ppAboves
[
p
pPStr
SLIT("*** Stg Lint Errors: in "),
ppStr
whodunnit, p
pPStr
SLIT(" ***"),
Just msg -> pprPanic "" (
vcat
[
p
text
SLIT("*** Stg Lint Errors: in "),
text
whodunnit, p
text
SLIT(" ***"),
msg sty,
p
pPStr
SLIT("*** Offending Program ***"),
ppAboves
(map (pprPlainStgBinding sty) binds),
p
pPStr
SLIT("*** End of Offense ***")])
p
text
SLIT("*** Offending Program ***"),
vcat
(map (pprPlainStgBinding sty) binds),
p
text
SLIT("*** End of Offense ***")])
where
lint_binds :: [StgBinding] -> LintM ()
...
...
@@ -270,7 +271,7 @@ type LintM a = [LintLocInfo] -- Locations
-> Bag ErrMsg -- Error messages so far
-> (a, Bag ErrMsg) -- Result and error messages (if any)
type ErrMsg = PprStyle ->
Pretty
type ErrMsg = PprStyle ->
Doc
data LintLocInfo
= RhsOf Id -- The variable bound
...
...
@@ -279,22 +280,22 @@ data LintLocInfo
instance Outputable LintLocInfo where
ppr sty (RhsOf v)
=
ppBesides
[ppr sty (getSrcLoc v), p
pPStr
SLIT(": [RHS of "), pp_binders sty [v],
ppC
har ']']
=
hcat
[ppr sty (getSrcLoc v), p
text
SLIT(": [RHS of "), pp_binders sty [v],
c
har ']']
ppr sty (LambdaBodyOf bs)
=
ppBesides
[ppr sty (getSrcLoc (head bs)),
p
pPStr
SLIT(": [in body of lambda with binders "), pp_binders sty bs,
ppC
har ']']
=
hcat
[ppr sty (getSrcLoc (head bs)),
p
text
SLIT(": [in body of lambda with binders "), pp_binders sty bs,
c
har ']']
ppr sty (BodyOfLetRec bs)
=
ppBesides
[ppr sty (getSrcLoc (head bs)),
p
pPStr
SLIT(": [in body of letrec with binders "), pp_binders sty bs,
ppC
har ']']
=
hcat
[ppr sty (getSrcLoc (head bs)),
p
text
SLIT(": [in body of letrec with binders "), pp_binders sty bs,
c
har ']']
pp_binders :: PprStyle -> [Id] ->
Pretty
pp_binders :: PprStyle -> [Id] ->
Doc
pp_binders sty bs
=
ppInterleave ppC
omma (map pp_binder bs)
=
sep (punctuate c
omma (map pp_binder bs)
)
where
pp_binder b
=
ppCat
[ppr sty b, p
pPStr
SLIT("::"), ppr sty (idType b)]
=
hsep
[ppr sty b, p
text
SLIT("::"), ppr sty (idType b)]
\end{code}
\begin{code}
...
...
@@ -305,7 +306,7 @@ initL m
Nothing
else
Just ( \ sty ->
foldBag
ppAbove
( \ msg -> msg sty )
ppNil
errs
foldBag
($$)
( \ msg -> msg sty )
empty
errs
)
}
...
...
@@ -362,7 +363,7 @@ addErr :: Bag ErrMsg -> ErrMsg -> [LintLocInfo] -> Bag ErrMsg
addErr errs_so_far msg locs
= errs_so_far `snocBag` ( \ sty ->
ppH
ang (ppr sty (head locs)) 4 (msg sty)
h
ang (ppr sty (head locs)) 4 (msg sty)
)
addLoc :: LintLocInfo -> LintM a -> LintM a
...
...
@@ -423,7 +424,7 @@ checkFunApp fun_ty arg_tys msg loc scope errs
checkInScope :: Id -> LintM ()
checkInScope id loc scope errs
= if isLocallyDefined id && not (isDataCon id) && not (id `elementOfIdSet` scope) then
((), addErr errs (\ sty ->
ppCat
[ppr sty id, p
pPStr
SLIT("is out of scope")]) loc)
((), addErr errs (\ sty ->
hsep
[ppr sty id, p
text
SLIT("is out of scope")]) loc)
else
((), errs)
...
...
@@ -437,88 +438,88 @@ checkTys ty1 ty2 msg loc scope errs
\begin{code}
mkCaseAltMsg :: StgCaseAlts -> ErrMsg
mkCaseAltMsg alts sty
=
ppAbove (ppStr
"In some case alternatives, type of alternatives not all same:")
=
($$) (text
"In some case alternatives, type of alternatives not all same:")
-- LATER: (ppr sty alts)
(panic "mkCaseAltMsg")
mkCaseDataConMsg :: StgExpr -> ErrMsg
mkCaseDataConMsg expr sty
=
ppAbove (ppPStr
SLIT("A case scrutinee not a type-constructor type:"))
=
($$) (ptext
SLIT("A case scrutinee not a type-constructor type:"))
(pp_expr sty expr)
mkCaseAbstractMsg :: TyCon -> ErrMsg
mkCaseAbstractMsg tycon sty
=
ppAbove (ppPStr
SLIT("An algebraic case on an abstract type:"))
=
($$) (ptext
SLIT("An algebraic case on an abstract type:"))
(ppr sty tycon)
mkDefltMsg :: StgCaseDefault -> ErrMsg
mkDefltMsg deflt sty
=
ppAbove (ppPStr
SLIT("Binder in default case of a case expression doesn't match type of scrutinee:"))
=
($$) (ptext
SLIT("Binder in default case of a case expression doesn't match type of scrutinee:"))
--LATER: (ppr sty deflt)
(panic "mkDefltMsg")
mkFunAppMsg :: Type -> [Type] -> StgExpr -> ErrMsg
mkFunAppMsg fun_ty arg_tys expr sty
=
ppAboves [ppStr
"In a function application, function type doesn't match arg types:",
ppH
ang (p
pPStr
SLIT("Function type:")) 4 (ppr sty fun_ty),
ppH
ang (p
pPStr
SLIT("Arg types:")) 4 (
ppAboves
(map (ppr sty) arg_tys)),
ppH
ang (p
pPStr
SLIT("Expression:")) 4 (pp_expr sty expr)]
=
vcat [text
"In a function application, function type doesn't match arg types:",
h
ang (p
text
SLIT("Function type:")) 4 (ppr sty fun_ty),
h
ang (p
text
SLIT("Arg types:")) 4 (
vcat
(map (ppr sty) arg_tys)),
h
ang (p
text
SLIT("Expression:")) 4 (pp_expr sty expr)]
mkRhsConMsg :: Type -> [Type] -> ErrMsg
mkRhsConMsg fun_ty arg_tys sty
=
ppAboves [ppStr
"In a RHS constructor application, con type doesn't match arg types:",
ppH
ang (p
pPStr
SLIT("Constructor type:")) 4 (ppr sty fun_ty),
ppH
ang (p
pPStr
SLIT("Arg types:")) 4 (
ppAboves
(map (ppr sty) arg_tys))]
=
vcat [text
"In a RHS constructor application, con type doesn't match arg types:",
h
ang (p
text
SLIT("Constructor type:")) 4 (ppr sty fun_ty),
h
ang (p
text
SLIT("Arg types:")) 4 (
vcat
(map (ppr sty) arg_tys))]
mkUnappTyMsg :: Id -> Type -> ErrMsg
mkUnappTyMsg var ty sty
=
ppAboves [ppStr
"Variable has a for-all type, but isn't applied to any types.",
ppBeside (ppPStr
SLIT("Var: ")) (ppr sty var),
ppBeside (ppPStr
SLIT("Its type: ")) (ppr sty ty)]
=
vcat [text
"Variable has a for-all type, but isn't applied to any types.",
(<>) (ptext
SLIT("Var: ")) (ppr sty var),
(<>) (ptext
SLIT("Its type: ")) (ppr sty ty)]
mkAlgAltMsg1 :: Type -> ErrMsg
mkAlgAltMsg1 ty sty
=
ppAbove (ppStr
"In some case statement, type of scrutinee is not a data type:")
=
($$) (text
"In some case statement, type of scrutinee is not a data type:")
(ppr sty ty)
mkAlgAltMsg2 :: Type -> Id -> ErrMsg
mkAlgAltMsg2 ty con sty
=
ppAboves
[
ppStr
"In some algebraic case alternative, constructor is not a constructor of scrutinee type:",
=
vcat
[
text
"In some algebraic case alternative, constructor is not a constructor of scrutinee type:",
ppr sty ty,
ppr sty con
]
mkAlgAltMsg3 :: Id -> [Id] -> ErrMsg
mkAlgAltMsg3 con alts sty
=
ppAboves
[
ppStr
"In some algebraic case alternative, number of arguments doesn't match constructor:",
=
vcat
[
text
"In some algebraic case alternative, number of arguments doesn't match constructor:",
ppr sty con,
ppr sty alts
]
mkAlgAltMsg4 :: Type -> Id -> ErrMsg
mkAlgAltMsg4 ty arg sty
=
ppAboves
[
ppStr
"In some algebraic case alternative, type of argument doesn't match data constructor:",
=
vcat
[
text
"In some algebraic case alternative, type of argument doesn't match data constructor:",
ppr sty ty,
ppr sty arg
]
mkPrimAltMsg :: (Literal, StgExpr) -> ErrMsg
mkPrimAltMsg alt sty
=
ppAbove (ppStr
"In a primitive case alternative, type of literal doesn't match type of scrutinee:")
=
($$) (text
"In a primitive case alternative, type of literal doesn't match type of scrutinee:")
(ppr sty alt)
mkRhsMsg :: Id -> Type -> ErrMsg
mkRhsMsg binder ty sty
=
ppAboves [ppCat [ppPStr
SLIT("The type of this binder doesn't match the type of its RHS:"),
=
vcat [hsep [ptext
SLIT("The type of this binder doesn't match the type of its RHS:"),
ppr sty binder],
ppCat [ppPStr
SLIT("Binder's type:"), ppr sty (idType binder)],
ppCat [ppPStr
SLIT("Rhs type:"), ppr sty ty]
hsep [ptext
SLIT("Binder's type:"), ppr sty (idType binder)],
hsep [ptext
SLIT("Rhs type:"), ppr sty ty]
]
pp_expr :: PprStyle -> StgExpr ->
Pretty
pp_expr :: PprStyle -> StgExpr ->
Doc
pp_expr sty expr = ppr sty expr
sleazy_eq_ty ty1 ty2
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment