RnIfaces.lhs 38.3 KB
Newer Older
1
%
2
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3
4
5
6
7
%
\section[RnIfaces]{Cacheing and Renaming of Interfaces}

\begin{code}
module RnIfaces (
8
9
10
	getInterfaceExports, 
	getImportedInstDecls, getImportedRules,
	lookupFixity, loadHomeInterface,
11
	importDecl, recordSlurp,
12
	getImportVersions, getSlurped,
13

14
	checkUpToDate,
15

16
17
	getDeclBinders, getDeclSysBinders,
	removeContext	 	-- removeContext probably belongs somewhere else
18
19
    ) where

20
#include "HsVersions.h"
21

22
import CmdLineOpts	( opt_NoPruneDecls, opt_IgnoreIfacePragmas )
23
import HsSyn		( HsDecl(..), TyClDecl(..), InstDecl(..), IfaceSig(..), 
24
			  HsType(..), ConDecl(..), IE(..), ConDetails(..), Sig(..),
sof's avatar
sof committed
25
			  ForeignDecl(..), ForKind(..), isDynamic,
26
			  FixitySig(..), RuleDecl(..),
27
			  isClassOpSig, Deprecation(..)
28
			)
29
30
import BasicTypes	( Version, NewOrData(..), defaultFixity )
import RdrHsSyn		( RdrNameHsDecl, RdrNameInstDecl, RdrNameTyClDecl, RdrNameRuleDecl,
31
			  extractHsTyRdrNames, RdrNameDeprecation
32
			)
33
import RnEnv		( mkImportedGlobalName, newImportedBinder, mkImportedGlobalFromRdrName,
sof's avatar
sof committed
34
			  lookupOccRn, lookupImplicitOccRn,
35
36
37
			  pprAvail,
			  availName, availNames, addAvailToNameSet,
			  FreeVars, emptyFVs
38
			)
39
import RnMonad
40
import RnHsSyn          ( RenamedHsDecl, RenamedDeprecation )
41
import ParseIface	( parseIface, IfaceStuff(..) )
42

43
import FiniteMap	( FiniteMap, sizeFM, emptyFM, delFromFM, listToFM,
sof's avatar
sof committed
44
			  lookupFM, addToFM, addToFM_C, addListToFM, 
45
			  fmToList, elemFM, foldFM
sof's avatar
sof committed
46
			)
47
import Name		( Name {-instance NamedThing-},
sof's avatar
sof committed
48
			  nameModule, isLocallyDefined,
49
			  isWiredInName, nameUnique, NamedThing(..)
50
			 )
51
52
53
54
import Module		( Module, moduleString, pprModule,
			  mkVanillaModule, pprModuleName,
			  moduleUserString, moduleName, isLibModule,
			  ModuleName, WhereFrom(..),
55
56
			)
import RdrName		( RdrName, rdrNameOcc )
57
58
import NameSet
import Var		( Id )
59
import SrcLoc		( mkSrcLoc, SrcLoc )
60
import PrelMods		( pREL_GHC )
61
import PrelInfo		( cCallishTyKeys )
62
import Bag
63
import Maybes		( MaybeErr(..), maybeToBool, orElse )
64
import ListSetOps	( unionLists )
65
import Outputable
sof's avatar
sof committed
66
import Unique		( Unique )
67
import StringBuffer     ( StringBuffer, hGetStringBuffer )
68
import FastString	( mkFastString )
sof's avatar
sof committed
69
import ErrUtils         ( Message )
70
import Lex
sof's avatar
sof committed
71
import Outputable
72
73
74

import IO	( isDoesNotExistError )
import List	( nub )
75
76
\end{code}

77

78
79
80
81
82
%*********************************************************
%*							*
\subsection{Loading a new interface file}
%*							*
%*********************************************************
83

84
\begin{code}
85
loadHomeInterface :: SDoc -> Name -> RnM d Ifaces
86
loadHomeInterface doc_str name
87
88
89
90
91
92
93
94
95
96
97
  = loadInterface doc_str (moduleName (nameModule name)) ImportBySystem		`thenRn` \ (_, ifaces) ->
    returnRn ifaces

loadOrphanModules :: [ModuleName] -> RnM d ()
loadOrphanModules mods
  | null mods = returnRn ()
  | otherwise = traceRn (text "Loading orphan modules:" <+> fsep (map pprModuleName mods))	`thenRn_` 
		mapRn_ load mods	`thenRn_`
		returnRn ()
  where
    load mod = loadInterface (pprModuleName mod <+> ptext SLIT("is a orphan-instance module")) mod ImportBySystem
98

99
100
101
loadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (Module, Ifaces)
loadInterface doc_str mod_name from
 = getIfacesRn 			`thenRn` \ ifaces ->
sof's avatar
sof committed
102
   let
103
104
105
	mod_map  = iImpModInfo ifaces
	mod_info = lookupFM mod_map mod_name
	in_map   = maybeToBool mod_info
sof's avatar
sof committed
106
   in
107
108
109
110
111
112
113
114

	-- Issue a warning for a redundant {- SOURCE -} import
	-- It's redundant if the moduld is in the iImpModInfo at all,
	-- because we arrange to read all the ordinary imports before 
	-- any of the {- SOURCE -} imports
   warnCheckRn	(not (in_map && case from of {ImportByUserSource -> True; other -> False}))
		(warnRedundantSourceImport mod_name)	`thenRn_`

115
	-- CHECK WHETHER WE HAVE IT ALREADY
116
117
118
119
120
121
   case mod_info of {
	Just (_, _, Just (load_mod, _, _))
		-> 	-- We're read it already so don't re-read it
		    returnRn (load_mod, ifaces) ;

	mod_map_result ->
122
123

	-- READ THE MODULE IN
124
125
   findAndReadIface doc_str mod_name from in_map
   `thenRn` \ (hi_boot_read, read_result) ->
sof's avatar
sof committed
126
   case read_result of {
127
	Nothing -> 	-- Not found, so add an empty export env to the Ifaces map
128
			-- so that we don't look again
129
130
131
132
133
134
135
	   let
		mod         = mkVanillaModule mod_name
		new_mod_map = addToFM mod_map mod_name (0, False, Just (mod, False, []))
		new_ifaces  = ifaces { iImpModInfo = new_mod_map }
	   in
	   setIfacesRn new_ifaces		`thenRn_`
	   failWithRn (mod, new_ifaces) (noIfaceErr mod hi_boot_read) ;
136
137

	-- Found and parsed!
138
	Just (mod, iface) ->
139
140

	-- LOAD IT INTO Ifaces
141

sof's avatar
sof committed
142
143
144
145
	-- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
	---    names is done correctly (notably, whether this is an .hi file or .hi-boot file).
	--     If we do loadExport first the wrong info gets into the cache (unless we
	-- 	explicitly tag each export which seems a bit of a bore)
146

147
    getModuleRn 		`thenRn` \ this_mod_nm ->
148
    let
149
150
	rd_decls = pi_decls iface
    in
151
152
153
    foldlRn (loadDecl mod)	      (iDecls ifaces) rd_decls 			`thenRn` \ new_decls ->
    foldlRn (loadInstDecl mod)	      (iInsts ifaces) (pi_insts iface)		`thenRn` \ new_insts ->
    (if opt_IgnoreIfacePragmas
154
	then returnRn emptyBag
155
156
157
158
159
160
	else foldlRn (loadRule mod)   (iRules ifaces) (pi_rules iface))		`thenRn` \ new_rules ->
    (if opt_IgnoreIfacePragmas
	then returnRn emptyNameEnv
	else foldlRn (loadDeprec mod) (iDeprecs ifaces) (pi_deprecs iface))	`thenRn` \ new_deprecs ->
    foldlRn (loadFixDecl mod_name)    (iFixes ifaces) rd_decls  		`thenRn` \ new_fixities ->
    mapRn   (loadExport this_mod_nm)  (pi_exports iface)			`thenRn` \ avails_s ->
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    let
	-- For an explicit user import, add to mod_map info about
	-- the things the imported module depends on, extracted
	-- from its usage info.
	mod_map1 = case from of
			ImportByUser -> addModDeps mod mod_map (pi_usages iface)
			other        -> mod_map

	-- Now add info about this module
	mod_map2    = addToFM mod_map1 mod_name mod_details
	mod_details = (pi_mod iface, pi_orphan iface, Just (mod, hi_boot_read, concat avails_s))

	new_ifaces = ifaces { iImpModInfo = mod_map2,
			      iDecls      = new_decls,
			      iFixes      = new_fixities,
176
			      iInsts      = new_insts,
177
			      iRules	  = new_rules,
178
			      iDeprecs	  = new_deprecs }
179
    in
180
    setIfacesRn new_ifaces		`thenRn_`
181
    returnRn (mod, new_ifaces)
sof's avatar
sof committed
182
183
    }}

184
185
186
187
188
189
190
191
addModDeps :: Module -> ImportedModuleInfo
	   -> [ImportVersion a] -> ImportedModuleInfo
addModDeps mod mod_deps new_deps
  = foldr add mod_deps new_deps
  where
    is_lib = isLibModule mod	-- Don't record dependencies when importing a library module
    add (imp_mod, version, has_orphans, _) deps
	| is_lib && not has_orphans = deps
192
	| otherwise  =  addToFM_C combine deps imp_mod (version, has_orphans, Nothing)
193
194
195
196
197
198
199
200
201
	-- Record dependencies for modules that are
	--	either are dependent via a non-library module
	--	or contain orphan rules or instance decls

	-- Don't ditch a module that's already loaded!!
    combine old@(_, _, Just _)  new = old
    combine old@(_, _, Nothing) new = new

loadExport :: ModuleName -> ExportItem -> RnM d [AvailInfo]
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
loadExport this_mod (mod, entities)
  | mod == this_mod = returnRn []
	-- If the module exports anything defined in this module, just ignore it.
	-- Reason: otherwise it looks as if there are two local definition sites
	-- for the thing, and an error gets reported.  Easiest thing is just to
	-- filter them out up front. This situation only arises if a module
	-- imports itself, or another module that imported it.  (Necessarily,
	-- this invoves a loop.)  Consequence: if you say
	--	module A where
	--	   import B( AType )
	--	   type AType = ...
	--
	--	module B( AType ) where
	--	   import {-# SOURCE #-} A( AType )
	--
	-- then you'll get a 'B does not export AType' message.  A bit bogus
	-- but it's a bogus thing to do!

  | otherwise
221
  = mapRn (load_entity mod) entities
222
  where
223
    new_name mod occ = mkImportedGlobalName mod occ
224

sof's avatar
sof committed
225
226
    load_entity mod (Avail occ)
      =	new_name mod occ	`thenRn` \ name ->
sof's avatar
sof committed
227
	returnRn (Avail name)
sof's avatar
sof committed
228
229
230
    load_entity mod (AvailTC occ occs)
      =	new_name mod occ	      `thenRn` \ name ->
        mapRn (new_name mod) occs     `thenRn` \ names ->
sof's avatar
sof committed
231
        returnRn (AvailTC name names)
232

233

234
loadFixDecl :: ModuleName -> FixityEnv
235
	    -> (Version, RdrNameHsDecl)
236
237
	    -> RnM d FixityEnv
loadFixDecl mod_name fixity_env (version, FixD sig@(FixitySig rdr_name fixity loc))
238
239
240
  = 	-- Ignore the version; when the fixity changes the version of
	-- its 'host' entity changes, so we don't need a separate version
	-- number for fixities
241
    mkImportedGlobalName mod_name (rdrNameOcc rdr_name) 	`thenRn` \ name ->
242
243
244
245
246
247
    let
	new_fixity_env = addToNameEnv fixity_env name (FixitySig name fixity loc)
    in
    returnRn new_fixity_env

	-- Ignore the other sorts of decl
248
loadFixDecl mod_name fixity_env other_decl = returnRn fixity_env
249

250
251
loadDecl :: Module 
	 -> DeclsMap
252
	 -> (Version, RdrNameHsDecl)
253
	 -> RnM d DeclsMap
254

255
loadDecl mod decls_map (version, decl)
256
257
258
259
260
  = getDeclBinders new_name decl	`thenRn` \ maybe_avail ->
    case maybe_avail of {
	Nothing -> returnRn decls_map;	-- No bindings
	Just avail ->

261
262
263
264
    getDeclSysBinders new_name decl	`thenRn` \ sys_bndrs ->
    let
	main_name     = availName avail
	new_decls_map = foldl add_decl decls_map
265
				       [ (name, (version, avail, name==main_name, (mod, decl'))) 
266
267
				       | name <- sys_bndrs ++ availNames avail]
	add_decl decls_map (name, stuff)
268
	  = WARN( name `elemNameEnv` decls_map, ppr name )
269
270
271
	    addToNameEnv decls_map name stuff
    in
    returnRn new_decls_map
272
    }
273
  where
274
275
276
277
278
	-- newImportedBinder puts into the cache the binder with the
	-- module information set correctly.  When the decl is later renamed,
	-- the binding site will thereby get the correct module.
    new_name rdr_name loc = newImportedBinder mod rdr_name

sof's avatar
sof committed
279
    {-
280
281
      If a signature decl is being loaded, and optIgnoreIfacePragmas is on,
      we toss away unfolding information.
sof's avatar
sof committed
282
283
284
285
286

      Also, if the signature is loaded from a module we're importing from source,
      we do the same. This is to avoid situations when compiling a pair of mutually
      recursive modules, peering at unfolding info in the interface file of the other, 
      e.g., you compile A, it looks at B's interface file and may as a result change
287
288
      its interface file. Hence, B is recompiled, maybe changing its interface file,
      which will the unfolding info used in A to become invalid. Simple way out is to
sof's avatar
sof committed
289
      just ignore unfolding info.
290
291
292
293

      [Jan 99: I junked the second test above.  If we're importing from an hi-boot
       file there isn't going to *be* any pragma info.  Maybe the above comment
       dates from a time where we picked up a .hi file first if it existed?]
sof's avatar
sof committed
294
    -}
295
    decl' = case decl of
296
297
298
	       SigD (IfaceSig name tp ls loc) | opt_IgnoreIfacePragmas
			 ->  SigD (IfaceSig name tp [] loc)
	       other	 -> decl
sof's avatar
sof committed
299

300
301
loadInstDecl :: Module
	     -> Bag GatedDecl
302
	     -> RdrNameInstDecl
303
304
	     -> RnM d (Bag GatedDecl)
loadInstDecl mod insts decl@(InstDecl inst_ty binds uprags dfun_name src_loc)
305
306
307
308
309
310
311
312
  = 
	-- Find out what type constructors and classes are "gates" for the
	-- instance declaration.  If all these "gates" are slurped in then
	-- we should slurp the instance decl too.
	-- 
	-- We *don't* want to count names in the context part as gates, though.
	-- For example:
	--		instance Foo a => Baz (T a) where ...
313
	--
314
315
	-- Here the gates are Baz and T, but *not* Foo.
    let 
316
317
	munged_inst_ty = removeContext inst_ty
	free_names     = extractHsTyRdrNames munged_inst_ty
318
    in
319
320
321
322
    setModuleRn (moduleName mod) $
    mapRn mkImportedGlobalFromRdrName free_names	`thenRn` \ gate_names ->
    returnRn ((mkNameSet gate_names, (mod, InstD decl)) `consBag` insts)

323
324
325
326
327
328
329
330
331
332
333
334

-- In interface files, the instance decls now look like
--	forall a. Foo a -> Baz (T a)
-- so we have to strip off function argument types as well
-- as the bit before the '=>' (which is always empty in interface files)
removeContext (HsForAllTy tvs cxt ty) = HsForAllTy tvs [] (removeFuns ty)
removeContext ty		      = removeFuns ty

removeFuns (MonoFunTy _ ty) = removeFuns ty
removeFuns ty		    = ty


335
336
337
338
339
340
341
342
loadRule :: Module -> Bag GatedDecl 
	 -> RdrNameRuleDecl -> RnM d (Bag GatedDecl)
-- "Gate" the rule simply by whether the rule variable is
-- needed.  We can refine this later.
loadRule mod rules decl@(IfaceRuleDecl var body src_loc)
  = setModuleRn (moduleName mod) $
    mkImportedGlobalFromRdrName var		`thenRn` \ var_name ->
    returnRn ((unitNameSet var_name, (mod, RuleD decl)) `consBag` rules)
343

344
-- SUP: TEMPORARY HACK, ignoring module deprecations and constructors for now
345
loadDeprec :: Module -> DeprecationEnv -> RdrNameDeprecation -> RnM d DeprecationEnv
346
loadDeprec mod deprec_env (Deprecation (IEModuleContents _) txt)
347
348
  = traceRn (text "module deprecation not yet implemented:" <+> ppr mod <> colon <+> ppr txt) `thenRn_`
    returnRn deprec_env
349
loadDeprec mod deprec_env (Deprecation (IEVar rdr_name) txt)
350
351
352
  = setModuleRn (moduleName mod) $
    mkImportedGlobalFromRdrName rdr_name `thenRn` \ name ->
    traceRn (text "loaded deprecation for" <+> ppr name <> colon <+> ppr txt) `thenRn_`
353
    returnRn (addToNameEnv deprec_env name txt)
354
\end{code}
355

356

357
358
359
360
361
362
363
%********************************************************
%*							*
\subsection{Loading usage information}
%*							*
%********************************************************

\begin{code}
364
checkUpToDate :: ModuleName -> RnMG Bool		-- True <=> no need to recompile
365
checkUpToDate mod_name
366
367
368
369
  = getIfacesRn					`thenRn` \ ifaces ->
    findAndReadIface doc_str mod_name 
		     ImportByUser
		     (error "checkUpToDate")	`thenRn` \ (_, read_result) ->
sof's avatar
sof committed
370
371

	-- CHECK WHETHER WE HAVE IT ALREADY
372
    case read_result of
373
	Nothing -> 	-- Old interface file not found, so we'd better bail out
sof's avatar
sof committed
374
		    traceRn (sep [ptext SLIT("Didnt find old iface"), 
375
				  pprModuleName mod_name])	`thenRn_`
376
377
		    returnRn False

378
	Just (_, iface)
379
		-> 	-- Found it, so now check it
380
		    checkModUsage (pi_usages iface)
381
  where
382
	-- Only look in current directory, with suffix .hi
383
    doc_str = sep [ptext SLIT("need usage info from"), pprModuleName mod_name]
384

385
checkModUsage [] = returnRn True		-- Yes!  Everything is up to date!
386

387
388
389
390
391
392
393
394
395
checkModUsage ((mod_name, old_mod_vers, _, Specifically []) : rest)
	-- If CurrentModule.hi contains 
	--	import Foo :: ;
	-- then that simply records that Foo lies below CurrentModule in the
	-- hierarchy, but CurrentModule doesn't depend in any way on Foo.
	-- In this case we don't even want to open Foo's interface.
  = traceRn (ptext SLIT("Nothing used from:") <+> ppr mod_name)	`thenRn_`
    checkModUsage rest	-- This one's ok, so check the rest

396
397
checkModUsage ((mod_name, old_mod_vers, _, whats_imported) : rest)
  = loadInterface doc_str mod_name ImportBySystem	`thenRn` \ (mod, ifaces) ->
398
    let
399
400
401
	maybe_mod_vers = case lookupFM (iImpModInfo ifaces) mod_name of
			   Just (version, _, Just (_, _, _)) -> Just version
			   other			     -> Nothing
402
    in
403
404
405
406
    case maybe_mod_vers of {
	Nothing -> 	-- If we can't find a version number for the old module then
			-- bail out saying things aren't up to date
		traceRn (sep [ptext SLIT("Can't find version number for module"), 
407
408
			      pprModuleName mod_name])
		`thenRn_` returnRn False ;
409
410

	Just new_mod_vers ->
411
412
413

	-- If the module version hasn't changed, just move on
    if new_mod_vers == old_mod_vers then
414
415
	traceRn (sep [ptext SLIT("Module version unchanged:"), pprModuleName mod_name])
	`thenRn_` checkModUsage rest
416
    else
417
418
    traceRn (sep [ptext SLIT("Module version has changed:"), pprModuleName mod_name])
    `thenRn_`
419
420
421
422
423
424
425
426
427
428
	-- Module version changed, so check entities inside

	-- If the usage info wants to say "I imported everything from this module"
	--     it does so by making whats_imported equal to Everything
	-- In that case, we must recompile
    case whats_imported of {
      Everything -> traceRn (ptext SLIT("...and I needed the whole module"))	`thenRn_`
		    returnRn False;		   -- Bale out

      Specifically old_local_vers ->
429

430
	-- Non-empty usage list, so check item by item
431
    checkEntityUsage mod_name (iDecls ifaces) old_local_vers	`thenRn` \ up_to_date ->
432
    if up_to_date then
sof's avatar
sof committed
433
	traceRn (ptext SLIT("...but the bits I use haven't."))	`thenRn_`
434
435
436
	checkModUsage rest	-- This one's ok, so check the rest
    else
	returnRn False		-- This one failed, so just bail out now
437
    }}
438
  where
439
    doc_str = sep [ptext SLIT("need version info for"), pprModuleName mod_name]
440
441


442
checkEntityUsage mod decls [] 
443
444
  = returnRn True	-- Yes!  All up to date!

445
checkEntityUsage mod decls ((occ_name,old_vers) : rest)
446
  = mkImportedGlobalName mod occ_name 	`thenRn` \ name ->
447
    case lookupNameEnv decls name of
448
449

	Nothing       -> 	-- We used it before, but it ain't there now
450
			  traceRn (sep [ptext SLIT("No longer exported:"), ppr name])
451
			  `thenRn_` returnRn False
452

453
	Just (new_vers,_,_,_) 	-- It's there, but is it up to date?
454
455
456
457
458
459
		| new_vers == old_vers
			-- Up to date, so check the rest
		-> checkEntityUsage mod decls rest

		| otherwise
			-- Out of date, so bale out
460
		-> traceRn (sep [ptext SLIT("Out of date:"), ppr name])  `thenRn_`
461
		   returnRn False
462
463
464
\end{code}


465
466
467
468
469
%*********************************************************
%*							*
\subsection{Getting in a declaration}
%*							*
%*********************************************************
470

471
\begin{code}
472
473
474
475
476
477
478
479
480
481
482
483
importDecl :: Name -> RnMG (Maybe (Module, RdrNameHsDecl))
	-- Returns Nothing for 
	--	(a) wired in name
	--	(b) local decl
	--	(c) already slurped

importDecl name
  | isWiredInName name
  = returnRn Nothing
  | otherwise
  = getSlurped 				`thenRn` \ already_slurped ->
    if name `elemNameSet` already_slurped then
484
485
	returnRn Nothing	-- Already dealt with
    else
486
	if isLocallyDefined name then	-- Don't bring in decls from
487
					-- the renamed module's own interface file
488
		  addWarnRn (importDeclWarn name) `thenRn_`
489
490
491
		  returnRn Nothing
	else
	getNonWiredInDecl name
492
\end{code}
493

494
\begin{code}
495
496
getNonWiredInDecl :: Name -> RnMG (Maybe (Module, RdrNameHsDecl))
getNonWiredInDecl needed_name 
497
  = traceRn doc_str				`thenRn_`
498
    loadHomeInterface doc_str needed_name	`thenRn` \ ifaces ->
499
    case lookupNameEnv (iDecls ifaces) needed_name of
sof's avatar
sof committed
500

501
502
      Just (version,avail,_,decl)
	-> recordSlurp (Just version) avail	`thenRn_`
503
	   returnRn (Just decl)
504

505
506
507
      Nothing 	 	-- Can happen legitimately for "Optional" occurrences
	-> addErrRn (getDeclErr needed_name)	`thenRn_` 
	   returnRn Nothing
508
  where
509
     doc_str = ptext SLIT("need decl for") <+> ppr needed_name
510
511
\end{code}

512
513
514
@getWiredInDecl@ maps a wired-in @Name@ to what it makes available.
It behaves exactly as if the wired in decl were actually in an interface file.
Specifically,
515
516
\begin{itemize}
\item	if the wired-in name is a data type constructor or a data constructor, 
517
	it brings in the type constructor and all the data constructors; and
518
	marks as ``occurrences'' any free vars of the data con.
519

520
\item 	similarly for synonum type constructor
521

522
\item 	if the wired-in name is another wired-in Id, it marks as ``occurrences''
523
	the free vars of the Id's type.
524

525
\item	it loads the interface file for the wired-in thing for the
526
	sole purpose of making sure that its instance declarations are available
527
528
\end{itemize}
All this is necessary so that we know all types that are ``in play'', so
529
530
that we know just what instances to bring into scope.
	
531
532


533
    
534
535
%*********************************************************
%*							*
sof's avatar
sof committed
536
\subsection{Getting what a module exports}
537
538
%*							*
%*********************************************************
539

540
@getInterfaceExports@ is called only for directly-imported modules.
541

542
\begin{code}
543
544
545
546
getInterfaceExports :: ModuleName -> WhereFrom -> RnMG (Module, Avails)
getInterfaceExports mod_name from
  = loadInterface doc_str mod_name from	`thenRn` \ (mod, ifaces) ->
    case lookupFM (iImpModInfo ifaces) mod_name of
547
548
549
550
551
	Nothing -> -- Not there; it must be that the interface file wasn't found;
		   -- the error will have been reported already.
		   -- (Actually loadInterface should put the empty export env in there
		   --  anyway, but this does no harm.)
		   returnRn (mod, [])
552

553
	Just (_, _, Just (mod, _, avails)) -> returnRn (mod, avails)
554
  where
555
    doc_str = sep [pprModuleName mod_name, ptext SLIT("is directly imported")]
sof's avatar
sof committed
556
557
558
559
560
\end{code}


%*********************************************************
%*							*
561
\subsection{Instance declarations are handled specially}
sof's avatar
sof committed
562
563
564
565
%*							*
%*********************************************************

\begin{code}
566
567
getImportedInstDecls :: NameSet -> RnMG [(Module,RdrNameHsDecl)]
getImportedInstDecls gates
568
  =    	-- First, load any orphan-instance modules that aren't aready loaded
569
	-- Orphan-instance modules are recorded in the module dependecnies
570
    getIfacesRn 					`thenRn` \ ifaces ->
sof's avatar
sof committed
571
    let
572
573
	orphan_mods =
	  [mod | (mod, (_, True, Nothing)) <- fmToList (iImpModInfo ifaces)]
sof's avatar
sof committed
574
    in
575
    loadOrphanModules orphan_mods			`thenRn_` 
576

577
	-- Now we're ready to grab the instance declarations
578
579
	-- Find the un-gated ones and return them, 
	-- removing them from the bag kept in Ifaces
580
    getIfacesRn 					`thenRn` \ ifaces ->
581
    let
582
583
584
	(decls, new_insts) = selectGated gates (iInsts ifaces)
    in
    setIfacesRn (ifaces { iInsts = new_insts })		`thenRn_`
585

586
    traceRn (sep [text "getImportedInstDecls:", 
587
		  nest 4 (fsep (map ppr gate_list)),
588
589
		  text "Slurped" <+> int (length decls) <+> text "instance declarations",
		  nest 4 (vcat (map ppr_brief_inst_decl decls))])	`thenRn_`
590
591
    returnRn decls
  where
592
593
594
595
596
597
598
    gate_list      = nameSetToList gates

    load_home gate | isLocallyDefined gate
		   = returnRn ()
		   | otherwise
		   = loadHomeInterface (ppr gate <+> text "is an instance gate") gate	`thenRn_`
		     returnRn ()
599

600
601
602
603
604
ppr_brief_inst_decl (mod, InstD (InstDecl inst_ty _ _ _ _))
  = case inst_ty of
	HsForAllTy _ _ tau -> ppr tau
	other		   -> ppr inst_ty

605
getImportedRules :: RnMG [(Module,RdrNameHsDecl)]
606
607
608
getImportedRules 
  | opt_IgnoreIfacePragmas = returnRn []
  | otherwise
609
610
611
612
613
614
615
616
617
  = getIfacesRn 	`thenRn` \ ifaces ->
    let
	gates		   = iSlurp ifaces	-- Anything at all that's been slurped
	(decls, new_rules) = selectGated gates (iRules ifaces)
    in
    setIfacesRn (ifaces { iRules = new_rules })		`thenRn_`
    traceRn (sep [text "getImportedRules:", 
		  text "Slurped" <+> int (length decls) <+> text "rules"])	`thenRn_`
    returnRn decls
618

619
selectGated gates decl_bag
620
	-- Select only those decls whose gates are *all* in 'gates'
621
622
623
#ifdef DEBUG
  | opt_NoPruneDecls	-- Just to try the effect of not gating at all
  = (foldrBag (\ (_,d) ds -> d:ds) [] decl_bag, emptyBag)	-- Grab them all
624

625
626
627
  | otherwise
#endif
  = foldrBag select ([], emptyBag) decl_bag
628
  where
629
630
631
632
633
634
635
636
637
638
639
640
641
    select (reqd, decl) (yes, no)
	| isEmptyNameSet (reqd `minusNameSet` gates) = (decl:yes, no)
	| otherwise				     = (yes,      (reqd,decl) `consBag` no)

lookupFixity :: Name -> RnMS Fixity
lookupFixity name
  | isLocallyDefined name
  = getFixityEnv			`thenRn` \ local_fix_env ->
    case lookupNameEnv local_fix_env name of 
	Just (FixitySig _ fix _) -> returnRn fix
	Nothing		  	 -> returnRn defaultFixity

  | otherwise	-- Imported
642
643
644
645
646
647
648
      -- For imported names, we have to get their fixities by doing a loadHomeInterface,
      -- and consulting the Ifaces that comes back from that, because the interface
      -- file for the Name might not have been loaded yet.  Why not?  Suppose you import module A,
      -- which exports a function 'f', which is defined in module B.  Then B isn't loaded
      -- right away (after all, it's possible that nothing from B will be used).
      -- When we come across a use of 'f', we need to know its fixity, and it's then,
      -- and only then, that we load B.hi.  That is what's happening here.
649
  = loadHomeInterface doc name		`thenRn` \ ifaces ->
650
651
652
    case lookupNameEnv (iFixes ifaces) name of
	Just (FixitySig _ fix _) -> returnRn fix 
	Nothing 		 -> returnRn defaultFixity
653
  where
654
    doc = ptext SLIT("Checking fixity for") <+> ppr name
655
656
\end{code}

sof's avatar
sof committed
657
658
659
660
661
662
663

%*********************************************************
%*							*
\subsection{Keeping track of what we've slurped, and version numbers}
%*							*
%*********************************************************

664
665
666
667
getImportVersions figures out what the ``usage information'' for this
moudule is; that is, what it must record in its interface file as the
things it uses.  It records:

668
\begin{itemize}
669
670
\item	anything reachable from its body code
\item	any module exported with a @module Foo@.
671
672
673
\end{itemize}
%
Why the latter?  Because if @Foo@ changes then this module's export list
674
675
676
677
678
will change, so we must recompile this module at least as far as
making a new interface file --- but in practice that means complete
recompilation.

What about this? 
679
680
681
682
683
\begin{verbatim}
	module A( f, g ) where	|	module B( f ) where
	  import B( f )		|	  f = h 3
	  g = ...		|	  h = ...
\end{verbatim}
684
685
686
687
688
689
690
691

Should we record @B.f@ in @A@'s usages?  In fact we don't.  Certainly,
if anything about @B.f@ changes than anyone who imports @A@ should be
recompiled; they'll get an early exit if they don't use @B.f@.
However, even if @B.f@ doesn't change at all, @B.h@ may do so, and
this change may not be reflected in @f@'s version number.  So there
are two things going on when compiling module @A@:

692
\begin{enumerate}
693
694
\item	Are @A.o@ and @A.hi@ correct?  Then we can bale out early.
\item	Should modules that import @A@ be recompiled?
695
\end{enumerate}
696

697
For (1) it is slightly harmful to record @B.f@ in @A@'s usages,
698
699
700
701
702
703
704
705
because a change in @B.f@'s version will provoke full recompilation of
@A@, producing an identical @A.o@, and @A.hi@ differing only in its
usage-version of @B.f@ (and this usage-version info isn't used by any
importer).

For (2), because of the tricky @B.h@ question above, we ensure that
@A.hi@ is touched (even if identical to its previous version) if A's
recompilation was triggered by an imported @.hi@ file date change.
706
707
Given that, there's no need to record @B.f@ in @A@'s usages.

708
709
710
711
712
713
714
715
716
717
On the other hand, if @A@ exports @module B@, then we {\em do} count
@module B@ among @A@'s usages, because we must recompile @A@ to ensure
that @A.hi@ changes appropriately.

HOWEVER, we *do* record the usage
	import B <n> :: ;
in A.hi, to record the fact that A does import B.  This is used to decide
to look to look for B.hi rather than B.hi-boot when compiling a module that
imports A.  This line says that A imports B, but uses nothing in it.
So we'll get an early bale-out when compiling A if B's version changes.
718

719
\begin{code}
720
getImportVersions :: ModuleName			-- Name of this module
721
		  -> ExportEnv			-- Info about exports 
722
		  -> RnMG (VersionInfo Name)	-- Version info for these names
723

724
getImportVersions this_mod (ExportEnv export_avails _ export_all_mods)
725
726
  = getIfacesRn					`thenRn` \ ifaces ->
    let
727
728
	mod_map   = iImpModInfo ifaces
	imp_names = iVSlurp     ifaces
729

730
	-- mv_map groups together all the things imported from a particular module.
731
732
	mv_map :: FiniteMap ModuleName [(Name,Version)]
	mv_map = foldr add_mv emptyFM imp_names
733

734
	-- Build the result list by adding info for each module.
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
	-- For (a) a library module, we don't record it at all unless it contains orphans
	-- 	   (We must never lose track of orphans.)
	-- 
	--     (b) a source-imported module, don't record the dependency at all
	--	
	-- (b) may seem a bit strange.  The idea is that the usages in a .hi file records
	-- *all* the module's dependencies other than the loop-breakers.  We use
	-- this info in findAndReadInterface to decide whether to look for a .hi file or
	-- a .hi-boot file.  
	--
	-- This means we won't track version changes, or orphans, from .hi-boot files.
	-- The former is potentially rather bad news.  It could be fixed by recording
	-- whether something is a boot file along with the usage info for it, but 
	-- I can't be bothered just now.

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
	mk_version_info mod_name (version, has_orphans, contents) so_far
	   = let
		go_for_it exports = (mod_name, version, has_orphans, exports) : so_far
	     in 
	     case contents of
		Nothing -> 	-- We didn't even open the interface
			-- This happens when a module, Foo, that we explicitly imported has 
			-- 'import Baz' in its interface file, recording that Baz is below
			-- Foo in the module dependency hierarchy.  We want to propagate this
			-- information.  The Nothing says that we didn't even open the interface
			-- file but we must still propagate the dependeny info.
		   go_for_it (Specifically [])

		Just (mod, boot_import, _)		-- We did open the interface
		   |  boot_import			-- Don't record any usage info for this module
		   || (is_lib_module && not has_orphans)
		   -> so_far		
767
	   
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
		   |  is_lib_module 			-- Record the module but not detailed
		   || mod_name `elem` export_all_mods	-- version information for the imports
		   -> go_for_it Everything

		   |  otherwise
		   -> case lookupFM mv_map mod_name of
			Just whats_imported -> go_for_it (Specifically whats_imported)
			Nothing		    -> go_for_it (Specifically [])
						-- This happens if you have
						--	import Foo
						-- but don't actually *use* anything from Foo
					 	-- In which case record an empty dependency list
		   where
		     is_lib_module     = isLibModule mod
	     
sof's avatar
sof committed
783
    in
784
785
786
787
788
	-- A module shouldn't load its own interface
	-- This seems like a convenient place to check
    WARN( maybeToBool (lookupFM mod_map this_mod), 
	  ptext SLIT("Wierd:") <+> ppr this_mod <+> ptext SLIT("loads its own interface") )

789
    returnRn (foldFM mk_version_info [] mod_map)
790
  where
791
     add_mv v@(name, version) mv_map
792
793
      = addToFM_C add_item mv_map mod [v] 
      where
794
	 mod = moduleName (nameModule name)
795
         add_item vs _ = (v:vs)
796
\end{code}
797

sof's avatar
sof committed
798
\begin{code}
799
getSlurped
sof's avatar
sof committed
800
  = getIfacesRn 	`thenRn` \ ifaces ->
801
    returnRn (iSlurp ifaces)
sof's avatar
sof committed
802

803
804
805
recordSlurp maybe_version avail
  = getIfacesRn 	`thenRn` \ ifaces@(Ifaces { iSlurp  = slurped_names,
					            iVSlurp = imp_names }) ->
sof's avatar
sof committed
806
807
808
809
    let
	new_slurped_names = addAvailToNameSet slurped_names avail

	new_imp_names = case maybe_version of
sof's avatar
sof committed
810
			   Just version	-> (availName avail, version) : imp_names
sof's avatar
sof committed
811
812
			   Nothing      -> imp_names
    in
813
814
    setIfacesRn (ifaces { iSlurp  = new_slurped_names,
			  iVSlurp = new_imp_names })
sof's avatar
sof committed
815
816
817
\end{code}


818
819
820
821
822
823
824
825
826
827
%*********************************************************
%*							*
\subsection{Getting binders out of a declaration}
%*							*
%*********************************************************

@getDeclBinders@ returns the names for a @RdrNameHsDecl@.
It's used for both source code (from @availsFromDecl@) and interface files
(from @loadDecl@).

828
829
It doesn't deal with source-code specific things: @ValD@, @DefD@.  They
are handled by the sourc-code specific stuff in @RnNames@.
830

831
\begin{code}
832
getDeclBinders :: (RdrName -> SrcLoc -> RnM d Name)	-- New-name function
833
		-> RdrNameHsDecl
834
		-> RnM d (Maybe AvailInfo)
835

836
getDeclBinders new_name (TyClD (TyData _ _ tycon _ condecls _ _ src_loc))
837
838
  = new_name tycon src_loc			`thenRn` \ tycon_name ->
    getConFieldNames new_name condecls		`thenRn` \ sub_names ->
839
    returnRn (Just (AvailTC tycon_name (tycon_name : nub sub_names)))
sof's avatar
sof committed
840
841
	-- The "nub" is because getConFieldNames can legitimately return duplicates,
	-- when a record declaration has the same field in multiple constructors
842

843
getDeclBinders new_name (TyClD (TySynonym tycon _ _ src_loc))
844
  = new_name tycon src_loc		`thenRn` \ tycon_name ->
845
    returnRn (Just (AvailTC tycon_name [tycon_name]))
846

847
getDeclBinders new_name (TyClD (ClassDecl _ cname _ _ sigs _ _ _ _ _ src_loc))
848
  = new_name cname src_loc			`thenRn` \ class_name ->
849
850

	-- Record the names for the class ops
sof's avatar
sof committed
851
    let
sof's avatar
sof committed
852
853
	-- just want class-op sigs
	op_sigs = filter isClassOpSig sigs
sof's avatar
sof committed
854
    in
sof's avatar
sof committed
855
    mapRn (getClassOpNames new_name) op_sigs	`thenRn` \ sub_names ->
856

857
    returnRn (Just (AvailTC class_name (class_name : sub_names)))
858
859
860

getDeclBinders new_name (SigD (IfaceSig var ty prags src_loc))
  = new_name var src_loc			`thenRn` \ var_name ->
861
    returnRn (Just (Avail var_name))
862

863
getDeclBinders new_name (FixD _)  = returnRn Nothing
sof's avatar
sof committed
864
865
866
867
868
869
870
871
872
873
874

    -- foreign declarations
getDeclBinders new_name (ForD (ForeignDecl nm kind _ dyn _ loc))
  | binds_haskell_name kind dyn
  = new_name nm loc		    `thenRn` \ name ->
    returnRn (Just (Avail name))

  | otherwise -- a foreign export
  = lookupImplicitOccRn nm `thenRn_` 
    returnRn Nothing

875
876
getDeclBinders new_name (DefD _)  = returnRn Nothing
getDeclBinders new_name (InstD _) = returnRn Nothing
877
getDeclBinders new_name (RuleD _) = returnRn Nothing
878

sof's avatar
sof committed
879
880
881
882
binds_haskell_name (FoImport _) _   = True
binds_haskell_name FoLabel      _   = True
binds_haskell_name FoExport  ext_nm = isDynamic ext_nm

883
----------------
884
getConFieldNames new_name (ConDecl con _ _ (RecCon fielddecls) src_loc : rest)
885
886
887
  = mapRn (\n -> new_name n src_loc) (con:fields)	`thenRn` \ cfs ->
    getConFieldNames new_name rest			`thenRn` \ ns  -> 
    returnRn (cfs ++ ns)
888
  where
889
890
    fields = concat (map fst fielddecls)

sof's avatar
sof committed
891
getConFieldNames new_name (ConDecl con _ _ condecl src_loc : rest)
sof's avatar
sof committed
892
  = new_name con src_loc		`thenRn` \ n ->
sof's avatar
sof committed
893
894
895
896
897
    (case condecl of
      NewCon _ (Just f) -> 
        new_name f src_loc `thenRn` \ new_f ->
	returnRn [n,new_f]
      _ -> returnRn [n])		`thenRn` \ nn ->
sof's avatar
sof committed
898
    getConFieldNames new_name rest	`thenRn` \ ns -> 
sof's avatar
sof committed
899
    returnRn (nn ++ ns)
sof's avatar
sof committed
900

901
getConFieldNames new_name [] = returnRn []
902

903
getClassOpNames new_name (ClassOpSig op _ _ _ src_loc) = new_name op src_loc
904
905
\end{code}

906
907
@getDeclSysBinders@ gets the implicit binders introduced by a decl.
A the moment that's just the tycon and datacon that come with a class decl.
908
909
They aren't returned by @getDeclBinders@ because they aren't in scope;
but they {\em should} be put into the @DeclsMap@ of this module.
910

911
912
913
914
Note that this excludes the default-method names of a class decl,
and the dict fun of an instance decl, because both of these have 
bindings of their own elsewhere.

915
\begin{code}
916
getDeclSysBinders new_name (TyClD (ClassDecl _ cname _ _ sigs _ _ tname dname snames src_loc))
917
918
919
920
  = new_name dname src_loc		    	    	`thenRn` \ datacon_name ->
    new_name tname src_loc		        	`thenRn` \ tycon_name ->
    sequenceRn [new_name n src_loc | n <- snames]	`thenRn` \ scsel_names ->
    returnRn (tycon_name : datacon_name : scsel_names)
921
922
923
924

getDeclSysBinders new_name other_decl
  = returnRn []
\end{code}
925

926
927
928
929
930
931
%*********************************************************
%*							*
\subsection{Reading an interface file}
%*							*
%*********************************************************

932
\begin{code}
933
934
935
936
937
938
939
findAndReadIface :: SDoc -> ModuleName -> WhereFrom 
		 -> Bool	-- Only relevant for SystemImport
				-- True  <=> Look for a .hi file
				-- False <=> Look for .hi-boot file unless there's
				--	     a library .hi file
		 -> RnM d (Bool, Maybe (Module, ParsedIface))
	-- Bool is True if the interface actually read was a .hi-boot one
940
941
	-- Nothing <=> file not found, or unreadable, or illegible
	-- Just x  <=> successfully found and parsed 
942

943
findAndReadIface doc_str mod_name from hi_file
944
  = traceRn trace_msg			`thenRn_`
945
946
947
      -- we keep two maps for interface files,
      -- one for 'normal' ones, the other for .hi-boot files,
      -- hence the need to signal which kind we're interested.
948
949
950
951

    getHiMaps			`thenRn` \ hi_maps ->
	
    case find_path from hi_maps of
952
         -- Found the file
953
954
       (hi_boot, Just (fpath, mod)) -> traceRn (ptext SLIT("...reading from") <+> text fpath)
				       `thenRn_`
955
956
957
958
				       readIface mod fpath	`thenRn` \ result ->
				       returnRn (hi_boot, result)
       (hi_boot, Nothing)           -> traceRn (ptext SLIT("...not found"))	`thenRn_`
				       returnRn (hi_boot, Nothing)
959
  where
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
    find_path ImportByUser       (hi_map, _)     = (False, lookupFM hi_map mod_name)
    find_path ImportByUserSource (_, hiboot_map) = (True,  lookupFM hiboot_map mod_name)

    find_path ImportBySystem     (hi_map, hiboot_map)
      | hi_file
      =		-- If the module we seek is in our dependent set, 
		-- Look for a .hi file
         (False, lookupFM hi_map mod_name)

      | otherwise
		-- Check if there's a library module of that name
		-- If not, look for an hi-boot file
      = case lookupFM hi_map mod_name of
	   stuff@(Just (_, mod)) | isLibModule mod -> (False, stuff)
	   other		 		   -> (True, lookupFM hiboot_map mod_name)
sof's avatar
sof committed
975

sof's avatar
sof committed
976
    trace_msg = sep [hsep [ptext SLIT("Reading"), 
977
			   ppr from,
sof's avatar
sof committed
978
			   ptext SLIT("interface for"), 
979
			   pprModuleName mod_name <> semi],
sof's avatar
sof committed
980
		     nest 4 (ptext SLIT("reason:") <+> doc_str)]
981
\end{code}
982

sof's avatar
sof committed
983
@readIface@ tries just the one file.
984

985
\begin{code}
986
readIface :: Module -> String -> RnM d (Maybe (Module, ParsedIface))
987
988
	-- Nothing <=> file not found, or unreadable, or illegible
	-- Just x  <=> successfully found and parsed 
989
readIface the_mod file_path
990
  = ioToRnM (hGetStringBuffer False file_path)       `thenRn` \ read_result ->
991
    case read_result of
sof's avatar
sof committed
992
	Right contents	  -> 
993
994
995
996
997
998
             case parseIface contents
			PState{ bol = 0#, atbol = 1#,
				context = [],
				glasgow_exts = 1#,
				loc = mkSrcLoc (mkFastString file_path) 1 } of
		  POk _  (PIface mod_nm iface) ->
999
		    warnCheckRn (mod_nm == moduleName the_mod)
sof's avatar
sof committed
1000
1001
		    	        (hiModuleNameMismatchWarn the_mod mod_nm) `thenRn_`
		    returnRn (Just (the_mod, iface))
sof's avatar
sof committed
1002

1003
1004
1005
1006
1007
1008
1009
	          PFailed err   -> failWithRn Nothing err 
	          other 	-> failWithRn Nothing (ptext SLIT("Unrecognisable interface file"))
			 	-- This last case can happen if the interface file is (say) empty
				-- in which case the parser thinks it looks like an IdInfo or
				-- something like that.  Just an artefact of the fact that the
				-- parser is used for several purposes at once.

sof's avatar
sof committed
1010
1011
1012
        Left err
	  | isDoesNotExistError err -> returnRn Nothing
	  | otherwise               -> failWithRn Nothing (cannaeReadFile file_path err)
1013
\end{code}
1014

1015
%*********************************************************
sof's avatar
sof committed
1016
%*						 	 *
1017
\subsection{Errors}
sof's avatar
sof committed
1018
%*							 *
1019
%*********************************************************
1020

1021
\begin{code}
1022
1023
1024
1025
1026
1027
noIfaceErr filename boot_file
  = hsep [ptext SLIT("Could not find valid"), boot, 
	  ptext SLIT("interface file"), quotes (pprModule filename)]
  where
    boot | boot_file = ptext SLIT("[boot]")
	 | otherwise = empty
1028

1029
cannaeReadFile file err
sof's avatar
sof committed
1030
  = hcat [ptext SLIT("Failed in reading file: "), 
1031
          text file, 
sof's avatar
sof committed
1032
	  ptext SLIT("; error="), 
1033
	  text (show err)]
1034

1035
1036
getDeclErr name
  = ptext SLIT("Failed to find interface decl for") <+> quotes (ppr name)
1037

1038
getDeclWarn name loc
1039
1040
  = sep [ptext SLIT("Failed to find (optional) interface decl for") <+> quotes (ppr name),
	 ptext SLIT("desired at") <+> ppr loc]
sof's avatar
sof committed
1041

1042
importDeclWarn name
1043
1044
1045
1046
  = sep [ptext SLIT(
    "Compiler tried to import decl from interface file with same name as module."), 
	 ptext SLIT(
    "(possible cause: module name clashes with interface file already in scope.)")
sof's avatar
sof committed
1047
	] $$
1048
    hsep [ptext SLIT("name:"), quotes (ppr name)]
sof's avatar
sof committed
1049

1050
warnRedundantSourceImport mod_name
1051
1052
  = ptext SLIT("Unnecessary {- SOURCE -} in the import of module")
          <+> quotes (pprModuleName mod_name)
sof's avatar
sof committed
1053
1054
1055
1056
1057
1058
1059
1060
1061

hiModuleNameMismatchWarn :: Module -> ModuleName -> Message
hiModuleNameMismatchWarn requested_mod mod_nm = 
    hsep [ ptext SLIT("Something is amiss; requested module name")
	 , pprModule requested_mod
	 , ptext SLIT("differs from name found in the interface file ")
   	 , pprModuleName mod_nm
  	 ]

1062
\end{code}