RnIfaces.lhs 38.6 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
	getInterfaceExports,
	getImportedInstDecls,
sof's avatar
sof committed
10
	getSpecialInstModules, getDeferredDataDecls,
11
	importDecl, recordSlurp,
12
	getImportVersions, getSlurpedNames, getRnStats, getImportedFixities,
13

14
	checkUpToDate, loadHomeInterface,
15
16
17

	getDeclBinders,
	mkSearchPath
18
19
    ) where

20
#include "HsVersions.h"
21

sof's avatar
sof committed
22
import CmdLineOpts	( opt_PruneTyDecls,  opt_PruneInstDecls, 
sof's avatar
sof committed
23
			  opt_D_show_rn_imports, opt_IgnoreIfacePragmas
sof's avatar
sof committed
24
			)
25
import HsSyn		( HsDecl(..), TyClDecl(..), InstDecl(..), IfaceSig(..), 
26
			  HsType(..), ConDecl(..), IE(..), ConDetails(..), Sig(..),
27
28
			  FixitySig(..),
			  hsDeclName, countTyClDecls, isDataDecl
29
			)
30
import BasicTypes	( Version, NewOrData(..), IfaceFlavour(..) )
31
import RdrHsSyn		( RdrNameHsDecl, RdrNameInstDecl, RdrNameTyClDecl,
32
			  RdrName(..), rdrNameOcc
33
			)
34
35
import RnEnv		( newImportedGlobalName, addImplicitOccsRn, pprAvail,
			  availName, availNames, addAvailToNameSet, ifaceFlavour
36
			)
sof's avatar
sof committed
37
import RnSource		( rnHsSigType )
38
import RnMonad
39
40
import RnHsSyn          ( RenamedHsDecl )
import ParseIface	( parseIface, IfaceStuff(..) )
41

42
import FiniteMap	( FiniteMap, sizeFM, emptyFM, delFromFM,
sof's avatar
sof committed
43
			  lookupFM, addToFM, addToFM_C, addListToFM, 
44
			  fmToList
sof's avatar
sof committed
45
			)
46
import Name		( Name {-instance NamedThing-}, OccName,
47
			  nameModule, moduleString, pprModule, isLocallyDefined,
48
			  isWiredInName, maybeWiredInTyConName,  pprModule,
49
			  maybeWiredInIdName, nameUnique, NamedThing(..)
50
			 )
51
52
53
import NameSet
import Id		( idType, isDataConId_maybe )
import DataCon		( dataConTyCon, dataConType )
54
55
import TyCon		( TyCon, tyConDataCons, isSynTyCon, getSynTyConDefn )
import Type		( namesOfType )
56
import Var		( Id )
57
import SrcLoc		( mkSrcLoc, SrcLoc )
58
import PrelMods		( pREL_GHC )
59
import PrelInfo		( cCallishTyKeys, thinAirModules )
60
import Bag
61
import Maybes		( MaybeErr(..), maybeToBool )
62
import ListSetOps	( unionLists )
63
import Outputable
sof's avatar
sof committed
64
import Unique		( Unique )
65
import StringBuffer     ( StringBuffer, hGetStringBuffer )
66
import FastString	( mkFastString )
sof's avatar
sof committed
67
import Outputable
68
69
70

import IO	( isDoesNotExistError )
import List	( nub )
71

72
73
\end{code}

74
75


sof's avatar
sof committed
76
77
78
79
80
81
82
%*********************************************************
%*							*
\subsection{Statistics}
%*							*
%*********************************************************

\begin{code}
83
getRnStats :: [RenamedHsDecl] -> RnMG SDoc
sof's avatar
sof committed
84
85
86
getRnStats all_decls
  = getIfacesRn 		`thenRn` \ ifaces ->
    let
87
	n_mods	    = sizeFM (iModMap ifaces)
sof's avatar
sof committed
88
89

	decls_imported = filter is_imported_decl all_decls
90
91

	decls_read     = [decl | (_, avail, decl, True) <- nameEnvElts (iDecls ifaces),
sof's avatar
sof committed
92
93
94
					-- Data, newtype, and class decls are in the decls_fm
					-- under multiple names; the tycon/class, and each
					-- constructor/class op too.
95
96
					-- The 'True' selects just the 'main' decl
				 not (isLocallyDefined (availName avail))
sof's avatar
sof committed
97
98
99
100
101
			     ]

	(cd_rd, dd_rd, add_rd, nd_rd, and_rd, sd_rd, vd_rd,     _) = count_decls decls_read
	(cd_sp, dd_sp, add_sp, nd_sp, and_sp, sd_sp, vd_sp, id_sp) = count_decls decls_imported

102
	(unslurped_insts, _)  = iDefInsts ifaces
sof's avatar
sof committed
103
104
105
106
107
	inst_decls_unslurped  = length (bagToList unslurped_insts)
	inst_decls_read	      = id_sp + inst_decls_unslurped

	stats = vcat 
		[int n_mods <> text " interfaces read",
108
		 hsep [ int cd_sp, text "class decls imported, out of", 
sof's avatar
sof committed
109
		        int cd_rd, text "read"],
110
111
		 hsep [ int dd_sp, text "data decls imported (of which", int add_sp, 
			text "abstractly), out of",  
sof's avatar
sof committed
112
			int dd_rd, text "read"],
113
114
		 hsep [ int nd_sp, text "newtype decls imported (of which", int and_sp, 
			text "abstractly), out of",  
sof's avatar
sof committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
		        int nd_rd, text "read"],
		 hsep [int sd_sp, text "type synonym decls imported, out of",  
		        int sd_rd, text "read"],
		 hsep [int vd_sp, text "value signatures imported, out of",  
		        int vd_rd, text "read"],
		 hsep [int id_sp, text "instance decls imported, out of",  
		        int inst_decls_read, text "read"]
		]
    in
    returnRn (hcat [text "Renamer stats: ", stats])

is_imported_decl (DefD _) = False
is_imported_decl (ValD _) = False
is_imported_decl decl     = not (isLocallyDefined (hsDeclName decl))

count_decls decls
131
  = -- pprTrace "count_decls" (ppr  decls
sof's avatar
sof committed
132
133
134
135
    --
    --			    $$
    --			    text "========="
    --			    $$
136
    --			    ppr imported_decls
sof's avatar
sof committed
137
138
139
140
141
142
143
144
    --	) $
    (class_decls, 
     data_decls,    abstract_data_decls,
     newtype_decls, abstract_newtype_decls,
     syn_decls, 
     val_decls, 
     inst_decls)
  where
145
146
147
148
149
150
151
    tycl_decls = [d | TyClD d <- decls]
    (class_decls, data_decls, newtype_decls, syn_decls) = countTyClDecls tycl_decls
    abstract_data_decls    = length [() | TyData DataType _ _ _ [] _ _ _ <- tycl_decls]
    abstract_newtype_decls = length [() | TyData NewType  _ _ _ [] _ _ _ <- tycl_decls]

    val_decls     = length [() | SigD _	  <- decls]
    inst_decls    = length [() | InstD _  <- decls]
sof's avatar
sof committed
152
153
154

\end{code}    

155
156
157
158
159
%*********************************************************
%*							*
\subsection{Loading a new interface file}
%*							*
%*********************************************************
160

161
\begin{code}
162
163
164
165
loadHomeInterface :: SDoc -> Name -> RnMG Ifaces
loadHomeInterface doc_str name
  = loadInterface doc_str (nameModule name) (ifaceFlavour name)

166
loadInterface :: SDoc -> Module -> IfaceFlavour -> RnMG Ifaces
sof's avatar
sof committed
167
loadInterface doc_str load_mod as_source
sof's avatar
sof committed
168
169
 = getIfacesRn 		`thenRn` \ ifaces ->
   let
170
171
172
	this_mod 	     = iMod ifaces
	mod_map  	     = iModMap ifaces
	(insts, tycls_names) = iDefInsts ifaces
sof's avatar
sof committed
173
   in
174
	-- CHECK WHETHER WE HAVE IT ALREADY
sof's avatar
sof committed
175
   case lookupFM mod_map load_mod of {
176
177
	Just (hif, _, _) | hif `as_good_as` as_source
			 -> 	-- Already in the cache; don't re-read it
sof's avatar
sof committed
178
179
				returnRn ifaces ;
	other ->
180
181

	-- READ THE MODULE IN
sof's avatar
sof committed
182
183
   findAndReadIface doc_str load_mod as_source	`thenRn` \ read_result ->
   case read_result of {
184
185
186
187
	-- Check for not found
	Nothing -> 	-- Not found, so add an empty export env to the Ifaces map
			-- so that we don't look again
		   let
188
189
			new_mod_map = addToFM mod_map load_mod (HiFile, 0, [])
			new_ifaces = ifaces { iModMap = new_mod_map }
190
191
192
193
194
		   in
		   setIfacesRn new_ifaces		`thenRn_`
		   failWithRn new_ifaces (noIfaceErr load_mod) ;

	-- Found and parsed!
195
	Just (ParsedIface _ mod_vers usages exports rd_inst_mods rd_decls rd_insts) ->
196
197

	-- LOAD IT INTO Ifaces
sof's avatar
sof committed
198
199
200
201
	-- 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)
202
203
204
205
206
207
    foldlRn (loadDecl load_mod as_source)
	    (iDecls ifaces) rd_decls			`thenRn` \ new_decls ->
    foldlRn (loadFixDecl load_mod as_source) 
	    (iFixes ifaces) rd_decls			`thenRn` \ new_fixities ->
    mapRn loadExport exports				`thenRn` \ avails_s ->
    foldlRn (loadInstDecl load_mod) insts rd_insts	`thenRn` \ new_insts ->
208
    let
209
	 mod_details = (as_source, mod_vers, concat avails_s)
210
211

			-- Exclude this module from the "special-inst" modules
212
213
214
215
216
217
218
	 new_inst_mods = iInstMods ifaces `unionLists` (filter (/= this_mod) rd_inst_mods)

	 new_ifaces = ifaces { iModMap   = addToFM mod_map load_mod mod_details,
			       iDecls    = new_decls,
			       iFixes    = new_fixities,
			       iDefInsts = (new_insts, tycls_names),
			       iInstMods = new_inst_mods  }
219
    in
220
221
    setIfacesRn new_ifaces		`thenRn_`
    returnRn new_ifaces
sof's avatar
sof committed
222
223
224
225
226
227
    }}

as_good_as HiFile any        = True
as_good_as any    HiBootFile = True
as_good_as _      _	     = False

228

sof's avatar
sof committed
229
230
loadExport :: ExportItem -> RnMG [AvailInfo]
loadExport (mod, hif, entities)
231
  = mapRn load_entity entities
232
  where
233
    new_name occ = newImportedGlobalName mod occ hif
234

sof's avatar
sof committed
235
236
237
238
    load_entity (Avail occ)
      =	new_name occ 		`thenRn` \ name ->
	returnRn (Avail name)
    load_entity (AvailTC occ occs)
239
      =	new_name occ 		`thenRn` \ name ->
sof's avatar
sof committed
240
241
        mapRn new_name occs 	`thenRn` \ names ->
        returnRn (AvailTC name names)
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

loadFixDecl :: Module -> IfaceFlavour -> FixityEnv 
	    -> (Version, RdrNameHsDecl)
	    -> RnMG FixityEnv
loadFixDecl mod as_source fixity_env (version, FixD (FixitySig rdr_name fixity loc))
  = 	-- 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
    new_implicit_name mod as_source rdr_name 	`thenRn` \ name ->
    let
	new_fixity_env = addToNameEnv fixity_env name (FixitySig name fixity loc)
    in
    returnRn new_fixity_env

	-- Ignore the other sorts of decl
loadFixDecl mod as_source fixity_env other_decl = returnRn fixity_env

loadDecl :: Module -> IfaceFlavour -> DeclsMap
261
	 -> (Version, RdrNameHsDecl)
262
	 -> RnMG DeclsMap
263

sof's avatar
sof committed
264
loadDecl mod as_source decls_map (version, decl)
265
266
267
268
269
270
271
272
  = getDeclBinders new_name decl	`thenRn` \ avail ->
    getDeclSysBinders new_name decl	`thenRn` \ sys_bndrs ->
    let
	main_name     = availName avail
	new_decls_map = foldl add_decl decls_map
				       [ (name, (version,avail,decl',name==main_name)) 
				       | name <- sys_bndrs ++ availNames avail]
	add_decl decls_map (name, stuff)
273
	  = WARN( name `elemNameEnv` decls_map, ppr name )
274
275
276
	    addToNameEnv decls_map name stuff
    in
    returnRn new_decls_map
277
  where
278
    new_name rdr_name loc = new_implicit_name mod as_source 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
290
291
292
      just ignore unfolding info.
    -}
    decl' = 
     case decl of
sof's avatar
sof committed
293
       SigD (IfaceSig name tp ls loc) | from_hi_boot || opt_IgnoreIfacePragmas -> 
sof's avatar
sof committed
294
295
296
	    SigD (IfaceSig name tp [] loc)
       _ -> decl

sof's avatar
sof committed
297
298
299
    from_hi_boot = case as_source of
			HiBootFile -> True
			other	   -> False
300

301
302
303
new_implicit_name mod as_source rdr_name 
  = newImportedGlobalName mod (rdrNameOcc rdr_name) as_source

304
305
306
307
loadInstDecl :: Module
	     -> Bag IfaceInst
	     -> RdrNameInstDecl
	     -> RnMG (Bag IfaceInst)
308
loadInstDecl mod_name insts decl@(InstDecl inst_ty binds uprags dfun_name src_loc)
309
310
311
312
313
314
315
316
  = 
	-- 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 ...
317
	--
318
319
320
321
322
323
324
	-- Here the gates are Baz and T, but *not* Foo.
    let 
	munged_inst_ty = case inst_ty of
				HsForAllTy tvs cxt ty -> HsForAllTy tvs [] ty
				other		      -> inst_ty
    in
	-- We find the gates by renaming the instance type with in a 
325
	-- and returning the free variables of the type
326
    initRnMS emptyRnEnv mod_name vanillaInterfaceMode (
327
328
        discardOccurrencesRn (rnHsSigType (text "an instance decl") munged_inst_ty)
    )						`thenRn` \ (_, gate_names) ->
329
    returnRn (((mod_name, decl), gate_names) `consBag` insts)
330

331
vanillaInterfaceMode = InterfaceMode Compulsory
332
\end{code}
333

334

335
336
337
338
339
340
341
342
343
%********************************************************
%*							*
\subsection{Loading usage information}
%*							*
%********************************************************

\begin{code}
checkUpToDate :: Module -> RnMG Bool		-- True <=> no need to recompile
checkUpToDate mod_name
sof's avatar
sof committed
344
345
346
  = findAndReadIface doc_str mod_name HiFile	`thenRn` \ read_result ->

	-- CHECK WHETHER WE HAVE IT ALREADY
347
    case read_result of
348
	Nothing -> 	-- Old interface file not found, so we'd better bail out
sof's avatar
sof committed
349
		    traceRn (sep [ptext SLIT("Didnt find old iface"), 
350
				    pprModule mod_name])	`thenRn_`
351
352
		    returnRn False

353
	Just (ParsedIface _ _ usages _ _ _ _) 
354
355
		-> 	-- Found it, so now check it
		    checkModUsage usages
356
  where
357
	-- Only look in current directory, with suffix .hi
358
    doc_str = sep [ptext SLIT("need usage info from"), pprModule mod_name]
359

360
checkModUsage [] = returnRn True		-- Yes!  Everything is up to date!
361

362
checkModUsage ((mod, hif, old_mod_vers, whats_imported) : rest)
sof's avatar
sof committed
363
  = loadInterface doc_str mod hif	`thenRn` \ ifaces ->
364
    let
365
366
	maybe_new_mod_vers	  = lookupFM (iModMap ifaces) mod
	Just (_, new_mod_vers, _) = maybe_new_mod_vers
367
    in
368
	-- If we can't find a version number for the old module then
369
	-- bail out saying things aren't up to date
370
    if not (maybeToBool maybe_new_mod_vers) then
371
	traceRn (sep [ptext SLIT("Can't find version number for module"), pprModule mod]) `thenRn_`
372
373
374
375
376
	returnRn False
    else

	-- If the module version hasn't changed, just move on
    if new_mod_vers == old_mod_vers then
377
	traceRn (sep [ptext SLIT("Module version unchanged:"), pprModule mod])	`thenRn_`
378
379
	checkModUsage rest
    else
380
381
382
383
384
385
386
387
388
389
390
391
    traceRn (sep [ptext SLIT("Module version has changed:"), pprModule mod])	`thenRn_`

	-- 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 ->
392

393
	-- Non-empty usage list, so check item by item
394
    checkEntityUsage mod (iDecls ifaces) old_local_vers	`thenRn` \ up_to_date ->
395
    if up_to_date then
sof's avatar
sof committed
396
	traceRn (ptext SLIT("...but the bits I use haven't."))	`thenRn_`
397
398
399
	checkModUsage rest	-- This one's ok, so check the rest
    else
	returnRn False		-- This one failed, so just bail out now
400
    }
401
  where
402
    doc_str = sep [ptext SLIT("need version info for"), pprModule mod]
403
404


405
checkEntityUsage mod decls [] 
406
407
  = returnRn True	-- Yes!  All up to date!

408
checkEntityUsage mod decls ((occ_name,old_vers) : rest)
409
  = newImportedGlobalName mod occ_name HiFile	`thenRn` \ name ->
410
    case lookupNameEnv decls name of
411
412

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

416
	Just (new_vers,_,_,_) 	-- It's there, but is it up to date?
417
418
419
420
421
422
		| new_vers == old_vers
			-- Up to date, so check the rest
		-> checkEntityUsage mod decls rest

		| otherwise
			-- Out of date, so bale out
423
		-> putDocRn (sep [ptext SLIT("Out of date:"), ppr name])  `thenRn_`
424
		   returnRn False
425
426
427
\end{code}


428
429
430
431
432
%*********************************************************
%*							*
\subsection{Getting in a declaration}
%*							*
%*********************************************************
433

434
\begin{code}
435
importDecl :: Occurrence -> RnSMode -> RnMG (Maybe RdrNameHsDecl)
436
437
	-- Returns Nothing for a wired-in or already-slurped decl

438
importDecl (name, loc) mode
439
440
  = checkSlurped name			`thenRn` \ already_slurped ->
    if already_slurped then
441
--	traceRn (sep [text "Already slurped:", ppr name])	`thenRn_`
442
443
444
	returnRn Nothing	-- Already dealt with
    else
    if isWiredInName name then
445
	getWiredInDecl name mode
446
447
448
    else 
       getIfacesRn 		`thenRn` \ ifaces ->
       let
sof's avatar
sof committed
449
         mod = nameModule name
450
       in
451
       if mod == iMod ifaces then    -- Don't bring in decls from
sof's avatar
sof committed
452
453
	  addWarnRn (importDeclWarn mod name loc) `thenRn_`
--	  pprTrace "importDecl wierdness:" (ppr name) $
454
455
456
	  returnRn Nothing         -- the renamed module's own interface file
			           -- 
       else
457
       getNonWiredInDecl name loc mode
458
\end{code}
459

460
\begin{code}
461
462
getNonWiredInDecl :: Name -> SrcLoc -> RnSMode -> RnMG (Maybe RdrNameHsDecl)
getNonWiredInDecl needed_name loc mode
463
464
465
  = traceRn doc_str				`thenRn_`
    loadHomeInterface doc_str needed_name	`thenRn` \ ifaces ->
    case lookupNameEnv (iDecls ifaces) needed_name of
sof's avatar
sof committed
466
467

	-- Special case for data/newtype type declarations
468
469
470
471
      Just (version, avail, TyClD tycl_decl, _) | isDataDecl tycl_decl
	-> getNonWiredDataDecl needed_name version avail tycl_decl	`thenRn` \ (avail', maybe_decl) ->
	   recordSlurp (Just version) necessity avail'			`thenRn_`
	   returnRn maybe_decl
472

473
474
475
      Just (version,avail,decl,_)
	-> recordSlurp (Just version) necessity avail	`thenRn_`
	   returnRn (Just decl)
476
477
478

      Nothing -> 	-- Can happen legitimately for "Optional" occurrences
		   case necessity of { 
479
480
			Optional -> addWarnRn (getDeclWarn needed_name loc);
			other	 -> addErrRn  (getDeclErr  needed_name loc)
481
482
		   }						`thenRn_` 
		   returnRn Nothing
483
  where
484
485
     necessity = modeToNecessity mode
     doc_str = sep [ptext SLIT("need decl for"), ppr needed_name, ptext SLIT("needed at"), ppr loc]
486
487
\end{code}

488
489
490
@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,
491

492
493
494
  *	if the wired-in name is a data type constructor or a data constructor, 
	it brings in the type constructor and all the data constructors; and
	marks as "occurrences" any free vars of the data con.
495

496
  * 	similarly for synonum type constructor
497

498
499
  * 	if the wired-in name is another wired-in Id, it marks as "occurrences"
	the free vars of the Id's type.
500

501
502
  *	it loads the interface file for the wired-in thing for the
	sole purpose of making sure that its instance declarations are available
503

504
505
506
507
All this is necessary so that we know all types that are "in play", so
that we know just what instances to bring into scope.
	
\begin{code}
508
509
getWiredInDecl name mode
  = initRnMS emptyRnEnv mod_name new_mode
sof's avatar
sof committed
510
511
	     get_wired				`thenRn` \ avail ->
    recordSlurp Nothing necessity avail		`thenRn_`
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533

   	-- Force in the home module in case it has instance decls for
	-- the thing we are interested in.
	--
	-- Mini hack 1: no point for non-tycons/class; and if we
	-- do this we find PrelNum trying to import PackedString,
	-- because PrelBase's .hi file mentions PackedString.unpackString
	-- But PackedString.hi isn't built by that point!
	--
	-- Mini hack 2; GHC is guaranteed not to have
	-- instance decls, so it's a waste of time to read it
	--
	-- NB: We *must* look at the availName of the slurped avail, 
	-- not the name passed to getWiredInDecl!  Why?  Because if a data constructor 
	-- or class op is passed to getWiredInDecl we'll pull in the whole data/class
	-- decl, and recordSlurp will record that fact.  But since the data constructor
	-- isn't a tycon/class we won't force in the home module.  And even if the
	-- type constructor/class comes along later, loadDecl will say that it's already
	-- been slurped, so getWiredInDecl won't even be called.  Pretty obscure bug, this was.
    let
	main_name  = availName avail
	main_is_tc = case avail of { AvailTC _ _ -> True; Avail _ -> False }
sof's avatar
sof committed
534
	mod        = nameModule main_name
535
	doc_str    = sep [ptext SLIT("need home module for wired in thing"), ppr name]
536
    in
537
    (if not main_is_tc || mod == pREL_GHC then
538
	returnRn ()		
539
    else
540
	loadHomeInterface doc_str main_name	`thenRn_`
541
	returnRn ()
542
    )						`thenRn_`
543
544

    returnRn Nothing		-- No declaration to process further
545
  where
546
547
    necessity = modeToNecessity mode
    new_mode = case mode of 
548
549
			InterfaceMode _ -> mode
			SourceMode	-> vanillaInterfaceMode
550

551
552
553
    get_wired | is_tycon			-- ... a type constructor
	      = get_wired_tycon the_tycon

554
555
	      | maybeToBool maybe_data_con 		-- ... a wired-in data constructor
	      = get_wired_tycon (dataConTyCon data_con)
556
557
558
559

	      | otherwise			-- ... a wired-in non data-constructor
	      = get_wired_id the_id

sof's avatar
sof committed
560
    mod_name		 = nameModule name
561
562
563
564
565
    maybe_wired_in_tycon = maybeWiredInTyConName name
    is_tycon		 = maybeToBool maybe_wired_in_tycon
    maybe_wired_in_id    = maybeWiredInIdName    name
    Just the_tycon	 = maybe_wired_in_tycon
    Just the_id 	 = maybe_wired_in_id
566
567
    maybe_data_con	 = isDataConId_maybe the_id
    Just data_con	 = maybe_data_con
568

569

570
get_wired_id id
sof's avatar
sof committed
571
  = addImplicitOccsRn id_mentions 	`thenRn_`
572
    returnRn (Avail (getName id))
573
  where
sof's avatar
sof committed
574
575
    id_mentions = nameSetToList (namesOfType ty)
    ty = idType id
576

577
578
579
get_wired_tycon tycon 
  | isSynTyCon tycon
  = addImplicitOccsRn (nameSetToList mentioned)		`thenRn_`
sof's avatar
sof committed
580
    returnRn (AvailTC tc_name [tc_name])
581
  where
sof's avatar
sof committed
582
    tc_name     = getName tycon
583
    (tyvars,ty) = getSynTyConDefn tycon
sof's avatar
sof committed
584
    mentioned   = namesOfType ty `minusNameSet` mkNameSet (map getName tyvars)
585

586
587
588
get_wired_tycon tycon 
  | otherwise		-- data or newtype
  = addImplicitOccsRn (nameSetToList mentioned)		`thenRn_`
589
    returnRn (AvailTC tycon_name (tycon_name : map getName data_cons))
590
  where
591
592
    tycon_name = getName tycon
    data_cons  = tyConDataCons tycon
593
    mentioned  = foldr (unionNameSets . namesOfType . dataConType) emptyNameSet data_cons
594
595
596
\end{code}


597
    
598
599
%*********************************************************
%*							*
sof's avatar
sof committed
600
\subsection{Getting what a module exports}
601
602
%*							*
%*********************************************************
603
604

\begin{code}
605
getInterfaceExports :: Module -> IfaceFlavour -> RnMG Avails
sof's avatar
sof committed
606
getInterfaceExports mod as_source
607
608
  = loadInterface doc_str mod as_source	`thenRn` \ ifaces ->
    case lookupFM (iModMap ifaces) mod of
609
610
611
612
	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.)
613
		      returnRn []
614

615
	Just (_, _, avails) -> returnRn avails
616
  where
617
    doc_str = sep [pprModule mod, ptext SLIT("is directly imported")]
sof's avatar
sof committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
\end{code}


%*********************************************************
%*							*
\subsection{Data type declarations are handled specially}
%*							*
%*********************************************************

Data type declarations get special treatment.  If we import a data type decl
with all its constructors, we end up importing all the types mentioned in 
the constructors' signatures, and hence {\em their} data type decls, and so on.
In effect, we get the transitive closure of data type decls.  Worse, this drags
in tons on instance decls, and their unfoldings, and so on.
632

sof's avatar
sof committed
633
634
635
If only the type constructor is mentioned, then all this is a waste of time.
If any of the data constructors are mentioned then we really have to 
drag in the whole declaration.
636

sof's avatar
sof committed
637
638
639
640
641
642
643
644
645
646
647
So when we import the type constructor for a @data@ or @newtype@ decl, we
put it in the "deferred data/newtype decl" pile in Ifaces.  Right at the end
we slurp these decls, if they havn't already been dragged in by an occurrence
of a constructor.

\begin{code}
getNonWiredDataDecl needed_name 
		    version
	 	    avail@(AvailTC tycon_name _) 
		    ty_decl@(TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc)
  |  needed_name == tycon_name
sof's avatar
sof committed
648
  && opt_PruneTyDecls
sof's avatar
sof committed
649
650
651
652
        -- don't prune newtypes, as the code generator may
	-- want to peer inside a newtype type constructor
	-- (ClosureInfo.fun_result_ty is the culprit.)
  && not (new_or_data == NewType)
653
654
655
656
657
  && not (nameUnique needed_name `elem` cCallishTyKeys)		
	-- Hack!  Don't prune these tycons whose constructors
	-- the desugarer must be able to see when desugaring
	-- a CCall.  Ugh!

sof's avatar
sof committed
658
659
660
  = 	-- Need the type constructor; so put it in the deferred set for now
    getIfacesRn 		`thenRn` \ ifaces ->
    let
661
662
	deferred_data_decls = iDefData ifaces
	new_ifaces          = ifaces {iDefData = new_deferred_data_decls}
sof's avatar
sof committed
663
664

	no_constr_ty_decl       = TyData new_or_data [] tycon tyvars [] derivings pragmas src_loc
665
666
	new_deferred_data_decls = addToNameEnv deferred_data_decls tycon_name 
					       (nameModule tycon_name, no_constr_ty_decl)
sof's avatar
sof committed
667
668
669
670
671
672
673
674
675
676
677
678
679
		-- Nota bene: we nuke both the constructors and the context in the deferred decl.
		-- If we don't nuke the context then renaming the deferred data decls can give
		-- new unresolved names (for the classes).  This could be handled, but there's
		-- no point.  If the data type is completely abstract then we aren't interested
		-- its context.
    in
    setIfacesRn new_ifaces	`thenRn_`
    returnRn (AvailTC tycon_name [tycon_name], Nothing)

  | otherwise
  = 	-- Need a data constructor, so delete the data decl from the deferred set if it's there
    getIfacesRn 		`thenRn` \ ifaces ->
    let
680
681
	deferred_data_decls = iDefData ifaces
	new_ifaces          = ifaces {iDefData = new_deferred_data_decls}
682

683
	new_deferred_data_decls = delFromNameEnv deferred_data_decls tycon_name
sof's avatar
sof committed
684
685
    in
    setIfacesRn new_ifaces	`thenRn_`
686
    returnRn (avail, Just (TyClD ty_decl))
sof's avatar
sof committed
687
688
689
\end{code}

\begin{code}
690
getDeferredDataDecls :: RnMG [(Module, RdrNameTyClDecl)]
sof's avatar
sof committed
691
getDeferredDataDecls 
692
  = getIfacesRn 		`thenRn` \ ifaces ->
sof's avatar
sof committed
693
    let
694
	deferred_list = nameEnvElts (iDefData ifaces)
sof's avatar
sof committed
695
	trace_msg = hang (text "Slurping abstract data/newtype decls for: ")
696
			4 (ppr (map fst deferred_list))
sof's avatar
sof committed
697
698
699
700
701
702
703
704
705
706
707
708
709
    in
    traceRn trace_msg			`thenRn_`
    returnRn deferred_list
\end{code}


%*********************************************************
%*							*
\subsection{Instance declarations are handled specially}
%*							*
%*********************************************************

\begin{code}
710
getImportedInstDecls :: RnMG [(Module,RdrNameInstDecl)]
711
712
713
714
getImportedInstDecls
  = 	-- First load any special-instance modules that aren't aready loaded
    getSpecialInstModules 			`thenRn` \ inst_mods ->
    mapRn load_it inst_mods			`thenRn_`
715

716
	-- Now we're ready to grab the instance declarations
717
718
719
	-- Find the un-gated ones and return them, 
	-- removing them from the bag kept in Ifaces
    getIfacesRn 	`thenRn` \ ifaces ->
720
    let
721
	(insts, tycls_names) = iDefInsts ifaces
722
723
724
725
726
727
728
729
730
731

		-- An instance decl is ungated if all its gates have been slurped
        select_ungated :: IfaceInst					-- A gated inst decl

		       -> ([(Module, RdrNameInstDecl)], [IfaceInst])	-- Accumulator

		       -> ([(Module, RdrNameInstDecl)], 		-- The ungated ones
			   [IfaceInst]) 				-- Still gated, but with
									-- depeleted gates
	select_ungated (decl,gates) (ungated_decls, gated_decls)
732
	  | isEmptyNameSet remaining_gates
733
734
735
736
	  = (decl : ungated_decls, gated_decls)
	  | otherwise
	  = (ungated_decls, (decl, remaining_gates) : gated_decls)
	  where
737
	    remaining_gates = gates `minusNameSet` tycls_names
738
739
740

	(un_gated_insts, still_gated_insts) = foldrBag select_ungated ([], []) insts
	
741
742
743
	new_ifaces = ifaces {iDefInsts = (listToBag still_gated_insts, tycls_names)}
				-- NB: don't throw away tycls_names;
				-- we may comre across more instance decls
744
    in
745
    traceRn (sep [text "getInstDecls:", fsep (map ppr (nameSetToList tycls_names))])	`thenRn_`
746
747
    setIfacesRn new_ifaces	`thenRn_`
    returnRn un_gated_insts
748
  where
sof's avatar
sof committed
749
    load_it mod = loadInterface (doc_str mod) mod HiFile
750
    doc_str mod = sep [pprModule mod, ptext SLIT("is a special-instance module")]
751

752
753
754
755

getSpecialInstModules :: RnMG [Module]
getSpecialInstModules 
  = getIfacesRn						`thenRn` \ ifaces ->
756
757
758
759
760
761
    returnRn (iInstMods ifaces)

getImportedFixities :: RnMG FixityEnv
getImportedFixities
  = getIfacesRn						`thenRn` \ ifaces ->
    returnRn (iFixes ifaces)
762
763
\end{code}

sof's avatar
sof committed
764
765
766
767
768
769
770

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

771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
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:
	- anything reachable from its body code
	- any module exported with a "module Foo".

Why the latter?  Because if Foo changes then this module's export list
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? 
	module A( f, g ) where		module B( f ) where
	  import B( f )			  f = h 3
	  g = ...			  h = ...

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:

1.  Are A.o and A.hi correct?  Then we can bale out early.
2.  Should modules that import A be recompiled?

For (1) it is slightly harmful to record B.f in A's usages, 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 (which 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.  Given that, there's no need to record B.f in
A's usages.

On the other hand, if A exports "module B" then we *do* count module B among
A's usages, because we must recompile A to ensure that A.hi changes appropriately.

808
\begin{code}
809
810
getImportVersions :: Module			-- Name of this module
		  -> Maybe [IE any]		-- Export list for this module
811
		  -> RnMG (VersionInfo Name)	-- Version info for these names
812

813
getImportVersions this_mod exports
814
815
  = getIfacesRn					`thenRn` \ ifaces ->
    let
816
817
	mod_map   = iModMap ifaces
	imp_names = iVSlurp ifaces
818

819
820
	-- mv_map groups together all the things imported from a particular module.
	mv_map, mv_map_mod :: FiniteMap Module (WhatsImported Name)
821

822
	mv_map_mod = foldl add_mod emptyFM export_mods
823
		-- mv_map_mod records all the modules that have a "module M"
824
		-- in this module's export list with an "Everything" 
825

826
	mv_map = foldl add_mv mv_map_mod imp_names
827
828
		-- mv_map adds the version numbers of things exported individually

829
	mk_version_info (mod, local_versions)
sof's avatar
sof committed
830
	   = case lookupFM mod_map mod of
831
		Just (hif, version, _) -> (mod, hif, version, local_versions)
sof's avatar
sof committed
832
833
    in
    returnRn (map mk_version_info (fmToList mv_map))
834
835
836
837
838
839
  where
     export_mods = case exports of
			Nothing -> []
			Just es -> [mod | IEModuleContents mod <- es, mod /= this_mod]

     add_mv mv_map v@(name, version) 
840
      = addToFM_C add_item mv_map mod (Specifically [v]) 
841
	where
sof's avatar
sof committed
842
	 mod = nameModule name
843

844
845
846
847
         add_item Everything        _ = Everything
         add_item (Specifically xs) _ = Specifically (v:xs)

     add_mod mv_map mod = addToFM mv_map mod Everything
848
\end{code}
849

sof's avatar
sof committed
850
851
\begin{code}
checkSlurped name
852
853
  = getIfacesRn 	`thenRn` \ ifaces ->
    returnRn (name `elemNameSet` iSlurp ifaces)
sof's avatar
sof committed
854
855
856
857

getSlurpedNames :: RnMG NameSet
getSlurpedNames
  = getIfacesRn 	`thenRn` \ ifaces ->
858
    returnRn (iSlurp ifaces)
sof's avatar
sof committed
859

sof's avatar
sof committed
860
recordSlurp maybe_version necessity avail
861
  = {- traceRn (hsep [text "Record slurp:", pprAvail avail, 
sof's avatar
sof committed
862
863
					-- NB PprForDebug prints export flag, which is too
					-- strict; it's a knot-tied thing in RnNames
sof's avatar
sof committed
864
865
		  case necessity of {Compulsory -> text "comp"; Optional -> text "opt" } ])	`thenRn_` 
    -}
sof's avatar
sof committed
866
867
    getIfacesRn 	`thenRn` \ ifaces ->
    let
868
869
870
	Ifaces { iSlurp    = slurped_names,
		 iVSlurp   = imp_names,
		 iDefInsts = (insts, tycls_names) } = ifaces
871

sof's avatar
sof committed
872
873
874
	new_slurped_names = addAvailToNameSet slurped_names avail

	new_imp_names = case maybe_version of
sof's avatar
sof committed
875
			   Just version	-> (availName avail, version) : imp_names
sof's avatar
sof committed
876
877
			   Nothing      -> imp_names

sof's avatar
sof committed
878
879
880
881
882
883
884
885
886
		-- Add to the names that will let in instance declarations;
		-- but only (a) if it's a type/class
		--	    (b) if it's compulsory (unless the test flag opt_PruneInstDecls is off)
	new_tycls_names = case avail of
				AvailTC tc _  | not opt_PruneInstDecls || 
						case necessity of {Optional -> False; Compulsory -> True }
					      -> tycls_names `addOneToNameSet` tc
				otherwise     -> tycls_names

887
888
889
	new_ifaces = ifaces { iSlurp    = new_slurped_names,
			      iVSlurp   = new_imp_names,
			      iDefInsts = (insts, new_tycls_names) }
sof's avatar
sof committed
890
891
892
893
894
    in
    setIfacesRn new_ifaces
\end{code}


895
896
897
898
899
900
901
902
903
904
905
906
907
%*********************************************************
%*							*
\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@).

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

908
\begin{code}
sof's avatar
sof committed
909
getDeclBinders :: (RdrName -> SrcLoc -> RnMG Name)	-- New-name function
910
911
		-> RdrNameHsDecl
		-> RnMG AvailInfo
912

913
getDeclBinders new_name (TyClD (TyData _ _ tycon _ condecls _ _ src_loc))
914
915
  = new_name tycon src_loc			`thenRn` \ tycon_name ->
    getConFieldNames new_name condecls		`thenRn` \ sub_names ->
sof's avatar
sof committed
916
917
918
    returnRn (AvailTC tycon_name (tycon_name : nub sub_names))
	-- The "nub" is because getConFieldNames can legitimately return duplicates,
	-- when a record declaration has the same field in multiple constructors
919

920
getDeclBinders new_name (TyClD (TySynonym tycon _ _ src_loc))
921
  = new_name tycon src_loc		`thenRn` \ tycon_name ->
sof's avatar
sof committed
922
    returnRn (AvailTC tycon_name [tycon_name])
923

924
getDeclBinders new_name (TyClD (ClassDecl _ cname _ sigs _ _ tname dname src_loc))
925
  = new_name cname src_loc			`thenRn` \ class_name ->
926
927

	-- Record the names for the class ops
928
    mapRn (getClassOpNames new_name) sigs	`thenRn` \ sub_names ->
929

930
    returnRn (AvailTC class_name (class_name : sub_names))
931
932
933

getDeclBinders new_name (SigD (IfaceSig var ty prags src_loc))
  = new_name var src_loc			`thenRn` \ var_name ->
934
    returnRn (Avail var_name)
935

936
getDeclBinders new_name (FixD _)  = returnRn NotAvailable
sof's avatar
sof committed
937
getDeclBinders new_name (ForD _)  = returnRn NotAvailable
938
939
940
941
getDeclBinders new_name (DefD _)  = returnRn NotAvailable
getDeclBinders new_name (InstD _) = returnRn NotAvailable

----------------
942
getConFieldNames new_name (ConDecl con _ _ (RecCon fielddecls) src_loc : rest)
943
944
945
  = mapRn (\n -> new_name n src_loc) (con:fields)	`thenRn` \ cfs ->
    getConFieldNames new_name rest			`thenRn` \ ns  -> 
    returnRn (cfs ++ ns)
946
  where
947
948
    fields = concat (map fst fielddecls)

949
getConFieldNames new_name (ConDecl con _ _ _ src_loc : rest)
sof's avatar
sof committed
950
951
952
953
  = new_name con src_loc		`thenRn` \ n ->
    getConFieldNames new_name rest	`thenRn` \ ns -> 
    returnRn (n:ns)

954
getConFieldNames new_name [] = returnRn []
955

956
getClassOpNames new_name (ClassOpSig op _ _ src_loc) = new_name op src_loc
957
958
\end{code}

959
960
961
962
963
964
965
966
967
968
969
970
971
972
@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.
They aren'te returned by getDeclBinders because they aren't in scope;
but they should be put into the DeclsMap of this module.

\begin{code}
getDeclSysBinders new_name (TyClD (ClassDecl _ cname _ sigs _ _ tname dname src_loc))
  = new_name dname src_loc		        `thenRn` \ datacon_name ->
    new_name tname src_loc		        `thenRn` \ tycon_name ->
    returnRn [tycon_name, datacon_name]

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

974
975
976
977
978
979
%*********************************************************
%*							*
\subsection{Reading an interface file}
%*							*
%*********************************************************

980
\begin{code}
981
findAndReadIface :: SDoc -> Module 
sof's avatar
sof committed
982
983
	  	 -> IfaceFlavour 
		 -> RnMG (Maybe ParsedIface)
984
985
	-- Nothing <=> file not found, or unreadable, or illegible
	-- Just x  <=> successfully found and parsed 
sof's avatar
sof committed
986
findAndReadIface doc_str mod_name as_source
987
  = traceRn trace_msg			`thenRn_`
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
      -- 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.
    getModuleHiMap as_source		`thenRn` \ himap ->
    case (lookupFM himap (moduleString mod_name)) of
         -- Found the file
       Just fpath -> readIface fpath
    	 -- Hack alert!  When compiling PrelBase we have to load the
	 -- decls for packCString# and friends; they are 'thin-air' Ids
	 -- (see PrelInfo.lhs).  So if we don't find the HiFile we quietly
	 -- look for a .hi-boot file instead, and use that
       Nothing | thinAirLoop mod_name as_source
	       -> findAndReadIface doc_str mod_name HiBootFile
               | otherwise		 
	       -> traceRn (ptext SLIT("...failed"))	`thenRn_`
	          returnRn Nothing
1004
  where
1005
1006
    thinAirLoop mod_name HiFile = mod_name `elem` thinAirModules
    thinAirLoop mod_name hif    = False
sof's avatar
sof committed
1007

sof's avatar
sof committed
1008
1009
1010
    trace_msg = sep [hsep [ptext SLIT("Reading"), 
			   case as_source of { HiBootFile -> ptext SLIT("[boot]"); other -> empty},
			   ptext SLIT("interface for"), 
1011
			   pprModule mod_name <> semi],
sof's avatar
sof committed
1012
		     nest 4 (ptext SLIT("reason:") <+> doc_str)]
1013
\end{code}
1014

sof's avatar
sof committed
1015
@readIface@ tries just the one file.
1016

1017
1018
1019
1020
1021
\begin{code}
readIface :: String -> RnMG (Maybe ParsedIface)	
	-- Nothing <=> file not found, or unreadable, or illegible
	-- Just x  <=> successfully found and parsed 
readIface file_path
sof's avatar
sof committed
1022
  = ioToRnMG (hGetStringBuffer file_path)       `thenRn` \ read_result ->
1023
    case read_result of
sof's avatar
sof committed
1024
	Right contents	  -> 
1025
             case parseIface contents (mkSrcLoc (mkFastString file_path) 1) of
sof's avatar
sof committed
1026
	          Failed err      -> failWithRn Nothing err 
1027
		  Succeeded (PIface iface) -> 
sof's avatar
sof committed
1028
1029
1030
1031
1032
		        if opt_D_show_rn_imports then
			   putDocRn (hcat[ptext SLIT("Read "), text file_path]) `thenRn_`
			   returnRn (Just iface)
			else
			   returnRn (Just iface)
1033

sof's avatar
sof committed
1034
1035
1036
1037
1038
        Left err ->
	  if isDoesNotExistError err then
	     returnRn Nothing
	  else
	     failWithRn Nothing (cannaeReadFile file_path err)
1039
1040
\end{code}

sof's avatar
sof committed
1041
1042
1043
1044
1045
1046
1047
%*********************************************************
%*						 	 *
\subsection{Utils}
%*							 *
%*********************************************************

@mkSearchPath@ takes a string consisting of a colon-separated list
sof's avatar
sof committed
1048
1049
of directories and corresponding suffixes, and turns it into a list
of (directory, suffix) pairs.  For example:
1050

sof's avatar
sof committed
1051
\begin{verbatim}
sof's avatar
sof committed
1052
1053
 mkSearchPath "foo%.hi:.%.p_hi:baz%.mc_hi"
   = [("foo",".hi"),( ".", ".p_hi"), ("baz",".mc_hi")]
sof's avatar
sof committed
1054
\begin{verbatim}
1055
1056
1057

\begin{code}
mkSearchPath :: Maybe String -> SearchPath
sof's avatar
sof committed
1058
mkSearchPath Nothing = [(".",".hi")]
1059
1060
1061
mkSearchPath (Just s)
  = go s
  where
sof's avatar
sof committed
1062
    go "" = []
sof's avatar
sof committed
1063
1064
1065
1066
1067
1068
    go s  = 
      case span (/= '%') s of
       (dir,'%':rs) ->
         case span (/= ':') rs of
          (hisuf,_:rest) -> (dir,hisuf):go rest
          (hisuf,[])     -> [(dir,hisuf)]
1069
\end{code}
1070

1071
%*********************************************************
sof's avatar
sof committed
1072
%*						 	 *
1073
\subsection{Errors}
sof's avatar
sof committed
1074
%*							 *
1075
%*********************************************************
1076

1077
\begin{code}
1078
noIfaceErr filename
sof's avatar
sof committed
1079
  = hcat [ptext SLIT("Could not find valid interface file "), 
1080
          quotes (pprModule filename)]