summaryrefslogtreecommitdiff
path: root/ghc/compiler/abstractSyn/AbsSyn.lhs
blob: b7f494a1f2f5c5b43fb7ab661711f08f4a45bbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
%
\section[AbsSyntax]{Abstract syntax definition}

This module glues together the pieces of the Haskell abstract syntax,
which is declared in the various \tr{Hs*} modules.  This module,
therefore, is almost nothing but re-exporting.

The abstract syntax, used in the front end of the compiler, follows
that of a paper on the static semantics of Haskell by Simon Peyton
Jones and Phil Wadler.

The abstract syntax is parameterised with respect to variables
(abbrev: \tr{name}) and patterns (abbrev: \tr{pat}); here is a typical
example:
\begin{pseudocode}
type ProtoNameExpr   = Expr ProtoName	ProtoNamePat
type TypecheckedExpr = Expr Id		TypecheckedPat
\end{pseudocode}
Some parts of the syntax are unparameterised, because there is no
need for them to be.

\begin{code}
#include "HsVersions.h"

module AbsSyn (
	-- the mostly-parameterised data types
	ArithSeqInfo(..),
	Bind(..),
	Binds(..),
	ClassDecl(..),
	ClassPragmas,	-- abstract
	ConDecl(..),
	DefaultDecl(..),
	Expr(..),
	FixityDecl(..),
	GRHSsAndBinds(..),
	GRHS(..),
	IE(..),
	ImportedInterface(..),
	IfaceImportDecl(..),
	InPat(..),
	InstDecl(..),
	InstancePragmas,    -- abstract
	Interface(..),
	Literal(..),
	Match(..),
	Module(..),
	MonoBinds(..),
	MonoType(..),
	PolyType(..),
	Qual(..),
	Renaming(..),
	Sig(..),
	GenPragmas,	    -- abstract
	ClassOpPragmas,	    -- abstract
	TyDecl(..),
	DataPragmas,	    -- abstract
	TypePragmas,        -- abstract
	TypecheckedPat(..),
	SpecialisedInstanceSig(..), -- a user pragma
	DataTypeSig(..),

	Context(..),	-- synonyms
	ClassAssertion(..),

	-- synonyms for the (unparameterised) typechecker input
	ProtoNameArithSeqInfo(..),
	ProtoNameBind(..),
	ProtoNameBinds(..),
	ProtoNameClassDecl(..),
	ProtoNameClassPragmas(..),
	ProtoNameConDecl(..),
	ProtoNameContext(..),
	ProtoNameDefaultDecl(..),
	ProtoNameExpr(..),
	ProtoNameFixityDecl(..),
	ProtoNameGRHSsAndBinds(..),
	ProtoNameGRHS(..),
	ProtoNameImportedInterface(..),
	ProtoNameInstDecl(..),
	ProtoNameInstancePragmas(..),
	ProtoNameInterface(..),
	ProtoNameMatch(..),
	ProtoNameModule(..),
	ProtoNameMonoBinds(..),
	ProtoNameMonoType(..),
	ProtoNamePat(..),
	ProtoNamePolyType(..),
	ProtoNameQual(..),
	ProtoNameSig(..),
	ProtoNameClassOpSig(..),
	ProtoNameGenPragmas(..),
	ProtoNameClassOpPragmas(..),
	ProtoNameTyDecl(..),
	ProtoNameDataPragmas(..),
	ProtoNameSpecialisedInstanceSig(..),
	ProtoNameDataTypeSig(..),

	RenamedArithSeqInfo(..),
	RenamedBind(..),
	RenamedBinds(..),
	RenamedClassDecl(..),
	RenamedClassPragmas(..),
	RenamedConDecl(..),
	RenamedContext(..),
	RenamedDefaultDecl(..),
	RenamedExpr(..),
	RenamedFixityDecl(..),
	RenamedGRHSsAndBinds(..),
	RenamedGRHS(..),
	RenamedImportedInterface(..),
	RenamedInstDecl(..),
	RenamedInstancePragmas(..),
	RenamedInterface(..),
	RenamedMatch(..),
	RenamedModule(..),
	RenamedMonoBinds(..),
	RenamedMonoType(..),
	RenamedPat(..),
	RenamedPolyType(..),
	RenamedQual(..),
	RenamedSig(..),
	RenamedClassOpSig(..),
	RenamedGenPragmas(..),
	RenamedClassOpPragmas(..),
	RenamedTyDecl(..),
	RenamedDataPragmas(..),
	RenamedSpecialisedInstanceSig(..),
	RenamedDataTypeSig(..),

	-- synonyms for the (unparameterised) typechecker output
	TypecheckedArithSeqInfo(..),
	TypecheckedBind(..),
	TypecheckedBinds(..),
	TypecheckedExpr(..),
	TypecheckedGRHSsAndBinds(..),
	TypecheckedGRHS(..),
	TypecheckedMatch(..),
	TypecheckedMonoBinds(..),
	TypecheckedModule(..),
	TypecheckedQual(..),

	-- little help functions (AbsSynFuns)
	collectTopLevelBinders,
	collectBinders, collectTypedBinders,
	collectMonoBinders,
	collectMonoBindersAndLocs,
	collectQualBinders,
	collectPatBinders,
	collectTypedPatBinders,
	extractMonoTyNames,
	cmpInstanceTypes, getNonPrelOuterTyCon,
        getIEStrings, getRawIEStrings, ImExportListInfo(..),
--OLD:	getMentionedVars,
	mkDictApp,
	mkDictLam,
	mkTyApp,
	mkTyLam,
	nullBinds,
	nullMonoBinds,
	isLitPat, patsAreAllLits, isConPat, patsAreAllCons,
	irrefutablePat,
#ifdef DPH
	patsAreAllProcessor,
#endif
	unfailablePat, unfailablePats,
	pprContext,
	typeOfPat,
	negLiteral,

	eqConDecls, eqMonoType, cmpPolyType,

	-- imported things so we get a closed interface
	Outputable(..), NamedThing(..),
	ExportFlag, SrcLoc,
	Pretty(..), PprStyle, PrettyRep,

	OptIdInfo(..), -- I hate the instance virus!
	IdInfo, SpecEnv, StrictnessInfo, UpdateInfo, ArityInfo,
	DemandInfo, Demand, ArgUsageInfo, ArgUsage, DeforestInfo,
	FBTypeInfo, FBType, FBConsum, FBProd,

	Name(..), 	-- NB: goes out *WITH* constructors
	Id, DictVar(..), Inst, ProtoName, TyVar, UniType, TauType(..),
	Maybe, PreludeNameFun(..), Unique,
	FullName, ShortName, Arity(..), TyCon, Class, ClassOp,
	UnfoldingGuidance, BinderInfo, BasicLit, PrimOp, PrimKind,
	IdEnv(..), UniqFM, FiniteMap,
	CoreExpr, CoreAtom, UnfoldingCoreAtom, UnfoldingCoreExpr,
	UnfoldingPrimOp, UfCostCentre, Bag
	IF_ATTACK_PRAGMAS(COMMA cmpClass COMMA cmpTyCon COMMA cmpTyVar)
	IF_ATTACK_PRAGMAS(COMMA cmpUniType COMMA pprPrimOp)
#ifndef __GLASGOW_HASKELL__
	,TAG_
#endif
#ifdef DPH
        ,ParQuals(..), ProtoNameParQuals(..),
        RenamedParQuals(..), TypecheckedParQuals(..),
	collectParQualBinders
#endif {- Data Parallel Haskell -}
     ) where


import AbsSynFuns	-- help functions

import HsBinds		-- the main stuff to export
import HsCore
import HsDecls
import HsExpr
import HsImpExp
import HsLit
import HsMatches
import HsPat
import HsPragmas
import HsTypes

import AbsPrel		( PrimKind, PrimOp
			  IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
			  IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
			)
import AbsUniType	( TyVar, TyCon, Arity(..), Class, ClassOp, TauType(..)
			  IF_ATTACK_PRAGMAS(COMMA cmpTyVar)
			  IF_ATTACK_PRAGMAS(COMMA cmpClass)
			  IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
			  IF_ATTACK_PRAGMAS(COMMA cmpUniType)
			)
import BasicLit		( BasicLit )
import FiniteMap	( FiniteMap )
import Id		( Id, DictVar(..), DataCon(..) )
import IdInfo
import Inst		( Inst )
import Maybes		( Maybe )
import Name
import NameTypes	( ShortName, FullName ) -- .. for pragmas only
import Outputable
import Pretty
import ProtoName	( ProtoName(..) ) -- .. for pragmas only
import SrcLoc		( SrcLoc )
import Unique		( Unique )
import Util
\end{code}

All we actually declare here is the top-level structure for a module.
\begin{code}
data Module name pat
  = Module
	FAST_STRING		-- module name
	[IE]			-- export list
	[ImportedInterface name pat]
				-- We snaffle interesting stuff out of the
				-- imported interfaces early on, adding that
				-- info to TyDecls/etc; so this list is
				-- often empty, downstream.
	[FixityDecl name]
	[TyDecl name]
	[DataTypeSig name]	-- user pragmas that modify TyDecls;
				-- (much like "Sigs" modify value "Binds")
	[ClassDecl name pat]
	[InstDecl  name pat]
	[SpecialisedInstanceSig name] -- user pragmas that modify InstDecls
	[DefaultDecl name]
	(Binds name pat)	-- the main stuff!
	[Sig name]		-- "Sigs" are folded into the "Binds"
				-- pretty early on, so this list is
				-- often either empty or just the
				-- interface signatures.
	SrcLoc
\end{code}

\begin{code}
type ProtoNameModule    = Module ProtoName ProtoNamePat
type RenamedModule	= Module Name	   RenamedPat
type TypecheckedModule 	= Module Id	   TypecheckedPat
\end{code}

\begin{code}
instance (NamedThing name, Outputable name, NamedThing pat, Outputable pat) =>
	Outputable (Module name pat) where

    ppr sty (Module name exports imports fixities
		      typedecls typesigs classdecls instdecls instsigs
		      defdecls binds sigs src_loc)
      = ppAboves [
	    ifPprShowAll sty (ppr sty src_loc),
	    if (null exports)
	    then (ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")])
	    else (ppAboves [
		    ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
		    ppNest 8 (interpp'SP sty exports),
		    ppNest 4 (ppPStr SLIT(") where"))
		  ]),
	    ppr sty imports,	ppr sty fixities,
	    ppr sty typedecls,	ppr sty typesigs,
	    ppr sty classdecls,
	    ppr sty instdecls,	ppr sty instsigs,
	    ppr sty defdecls,
	    ppr sty binds,	ppr sty sigs
	]
\end{code}