2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[PlainCore]{``Plain'' core syntax: the usual parameterisation}
6 This module defines a particular parameterisation of the @CoreSyntax@
7 data type. Both binders and bindees are just @Ids@. This is the
11 #include "HsVersions.h"
14 PlainCoreProgram(..), PlainCoreBinding(..), PlainCoreExpr(..),
15 PlainCoreAtom(..), PlainCoreCaseAlternatives(..),
16 PlainCoreCaseDefault(..), PlainCoreArg(..),
18 PlainCoreParQuals(..),
19 PlainCoreParCommunicate(..),
20 CoreParCommunicate(..),
22 isParCoreCaseAlternative,
26 pprBigCoreBinder, pprTypedCoreBinder, -- not exported: pprBabyCoreBinder,
28 CoreBinding(..), CoreExpr(..), CoreAtom(..), -- re-exported
29 CoreCaseAlternatives(..), CoreCaseDefault(..),
32 CoreArg(..), applyToArgs, decomposeArgs, collectArgs,
34 -- and the related utility functions from CoreFuns...
36 typeOfCoreExpr, typeOfCoreAlts,
37 instCoreExpr, substCoreExpr, -- UNUSED: cloneCoreExpr,
38 substCoreExprUS, -- UNUSED: instCoreExprUS, cloneCoreExprUS,
40 mkCoLam, mkCoreIfThenElse,
41 -- mkCoApp, mkCoCon, mkCoPrim, -- no need for export
43 mkCoLetAny, mkCoLetNoUnboxed, mkCoLetUnboxedToCase,
44 mkCoLetsAny, mkCoLetsNoUnboxed, mkCoLetsUnboxedToCase,
45 mkCoLetrecAny, mkCoLetrecNoUnboxed,
46 mkCoTyLam, mkCoTyApp, mkCoTyApps,
47 mkErrorCoApp, escErrorMsg,
49 mkFunction, atomToExpr,
52 manifestlyWHNF, manifestlyBottom, --UNUSED: manifestWHNFArgs,
56 --UNUSED: boilsDownToConApp,
57 nonErrorRHSs, bindersOf,
58 squashableDictishCcExpr,
60 calcUnfoldingGuidance,
64 -- and one variant of free-var-finding stuff:
65 addTopBindsFVs, FVCoreExpr(..), FVCoreBinding(..),
67 -- and to make the interface self-sufficient ...
68 Outputable(..), NamedThing(..),
69 ExportFlag, SrcLoc, Unique,
70 Pretty(..), PprStyle, PrettyRep,
72 BasicLit, BinderInfo, Class, Id, Demand, IdInfo, FullName,
73 UnfoldingGuidance, UniType, TauType(..), ThetaType(..),
74 SigmaType(..), TyVar, TyCon, CostCentre, PrimOp, UniqueSupply,
75 UniqSM(..), IdEnv(..), UniqFM,
76 TyVarEnv(..), TypeEnv(..), IdSet(..), UniqSet(..),
78 IF_ATTACK_PRAGMAS(COMMA cmpClass)
79 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
80 IF_ATTACK_PRAGMAS(COMMA initUs) -- profiling
82 -- NOTE(hilly) Added UniqSM for cloneFunctions
86 --IMPORT_Trace -- ToDo: rm (debugging)
88 import CoreSyn -- mostly re-exporting this stuff
92 import AbsUniType ( TauType(..), ThetaType(..), SigmaType(..),
93 Class, UniType, FullName
94 IF_ATTACK_PRAGMAS(COMMA cmpClass)
95 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
98 import Id ( getIdUniType, getIdStrictness, getIdInfo,
101 import IdEnv -- ( nullIdEnv, IdEnv )
103 import Maybes ( Maybe(..) )
106 import Unique ( UniqSM(..), Unique
107 IF_ATTACK_PRAGMAS(COMMA initUs)
111 infixr 9 `thenUf`, `thenUf_`
114 The ``Core things'' just described are parameterised with respect to
115 the information kept about binding occurrences and bound occurrences
118 The ``Plain Core things'' are instances of the ``Core things'' in
119 which nothing but a name is kept, for both binders and variables.
121 type PlainCoreProgram = [CoreBinding Id Id]
122 type PlainCoreBinding = CoreBinding Id Id
123 type PlainCoreExpr = CoreExpr Id Id
124 type PlainCoreAtom = CoreAtom Id
126 type PlainCoreParQuals = CoreParQuals Id Id
127 type PlainCoreParCommunicate = CoreParCommunicate Id Id
128 #endif {- Data Parallel Haskell -}
129 type PlainCoreCaseAlternatives = CoreCaseAlternatives Id Id
130 type PlainCoreCaseDefault = CoreCaseDefault Id Id
132 type PlainCoreArg = CoreArg Id
135 %************************************************************************
137 \subsection[printing-PlainCore]{Printing @PlainCore@ things}
139 %************************************************************************
141 The most common core-printing interface:
143 pprPlainCoreBinding :: PprStyle -> PlainCoreBinding -> Pretty
145 pprPlainCoreBinding sty (CoNonRec binder expr)
146 = ppHang (ppCat [pprBigCoreBinder sty binder, ppEquals])
147 4 (pprCoreExpr sty pprBigCoreBinder pprBabyCoreBinder ppr expr)
149 pprPlainCoreBinding sty (CoRec binds)
150 = ppAboves [ifPprDebug sty (ppStr "{- plain CoRec -}"),
151 ppAboves (map ppr_bind binds),
152 ifPprDebug sty (ppStr "{- end plain CoRec -}")]
154 ppr_bind (binder, expr)
155 = ppHang (ppCat [pprBigCoreBinder sty binder, ppEquals])
156 4 (pprCoreExpr sty pprBigCoreBinder pprBabyCoreBinder ppr expr)
159 Other printing bits-and-bobs used with the general @pprCoreBinding@
160 and @pprCoreExpr@ functions.
162 pprBigCoreBinder sty binder
163 = ppAboves [sig, pragmas, ppr sty binder]
165 sig = ifnotPprShowAll sty (
166 ppHang (ppCat [ppr sty binder, ppStr "::"])
167 4 (ppr sty (getIdUniType binder)))
169 pragmas = ifnotPprForUser sty (
170 ppIdInfo sty binder True{-specs, please-} id nullIdEnv (getIdInfo binder))
172 pprBabyCoreBinder sty binder
173 = ppCat [ppr sty binder, pp_strictness]
176 = case (getIdStrictness binder) of
177 NoStrictnessInfo -> ppNil
178 BottomGuaranteed -> ppStr "{- _!_ -}"
179 StrictnessInfo xx _ -> ppStr ("{- " ++ (showList xx "") ++ " -}")
181 pprTypedCoreBinder sty binder
182 = ppBesides [ppLparen, ppCat [ppr sty binder,
183 ppStr "::", ppr sty (getIdUniType binder)],