2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnIfaces]{Cacheing and Renaming of Interfaces}
7 #include "HsVersions.h"
12 getSpecialInstModules,
13 importDecl, recordSlurp,
25 import CmdLineOpts ( opt_HiSuffix, opt_HiSuffixPrelude )
26 import HsSyn ( HsDecl(..), TyDecl(..), ClassDecl(..), HsTyVar, Bind, HsExpr, Sig(..), HsType(..),
27 HsBinds(..), MonoBinds, DefaultDecl, ConDecl(..), BangType, IfaceSig(..),
28 FixityDecl(..), Fixity, Fake, InPat, InstDecl(..), SYN_IE(Version), HsIdInfo,
31 import HsPragmas ( noGenPragmas )
32 import RdrHsSyn ( SYN_IE(RdrNameHsDecl), SYN_IE(RdrNameInstDecl),
35 import RnEnv ( newGlobalName, lookupRn, addImplicitOccsRn,
36 availName, availNames, addAvailToNameSet, pprAvail
38 import RnSource ( rnHsType )
40 import ParseIface ( parseIface )
42 import ErrUtils ( SYN_IE(Error), SYN_IE(Warning) )
43 import FiniteMap ( FiniteMap, emptyFM, unitFM, lookupFM, addToFM, addToFM_C, addListToFM, fmToList )
44 import Name ( Name {-instance NamedThing-}, Provenance, OccName(..),
45 modAndOcc, occNameString, moduleString, pprModule,
46 NameSet(..), emptyNameSet, unionNameSets, nameSetToList,
47 minusNameSet, mkNameSet, elemNameSet,
48 isWiredInName, maybeWiredInTyConName, maybeWiredInIdName
50 import Id ( GenId, Id(..), idType, dataConTyCon, isDataCon )
51 import TyCon ( TyCon, tyConDataCons, isSynTyCon, getSynTyConDefn )
52 import Type ( namesOfType )
53 import TyVar ( GenTyVar )
54 import SrcLoc ( mkIfaceSrcLoc )
55 import PrelMods ( gHC__, isPreludeModule )
57 import Maybes ( MaybeErr(..), expectJust, maybeToBool )
58 import ListSetOps ( unionLists )
60 import PprStyle ( PprStyle(..) )
61 import Util ( pprPanic, pprTrace )
62 import StringBuffer ( StringBuffer, hGetStringBuffer, freeStringBuffer )
68 %*********************************************************
70 \subsection{Loading a new interface file}
72 %*********************************************************
75 loadInterface :: Pretty -> Module -> RnMG Ifaces
76 loadInterface doc_str load_mod
77 = getIfacesRn `thenRn` \ ifaces ->
79 Ifaces this_mod mod_vers_map export_envs decls all_names imp_names insts inst_mods = ifaces
81 -- CHECK WHETHER WE HAVE IT ALREADY
82 if maybeToBool (lookupFM export_envs load_mod)
84 returnRn ifaces -- Already in the cache; don't re-read it
88 findAndReadIface doc_str load_mod `thenRn` \ read_result ->
90 -- Check for not found
91 Nothing -> -- Not found, so add an empty export env to the Ifaces map
92 -- so that we don't look again
94 new_export_envs = addToFM export_envs load_mod ([],[])
95 new_ifaces = Ifaces this_mod mod_vers_map
97 decls all_names imp_names insts inst_mods
99 setIfacesRn new_ifaces `thenRn_`
100 failWithRn new_ifaces (noIfaceErr load_mod) ;
103 Just (ParsedIface _ mod_vers usages exports rd_inst_mods fixs rd_decls rd_insts) ->
105 -- LOAD IT INTO Ifaces
106 mapRn loadExport exports `thenRn` \ avails_s ->
107 foldlRn (loadDecl load_mod) decls rd_decls `thenRn` \ new_decls ->
108 foldlRn (loadInstDecl load_mod) insts rd_insts `thenRn` \ new_insts ->
110 export_env = (concat avails_s, fixs)
112 -- Exclude this module from the "special-inst" modules
113 new_inst_mods = inst_mods `unionLists` (filter (/= this_mod) rd_inst_mods)
115 new_ifaces = Ifaces this_mod
116 (addToFM mod_vers_map load_mod mod_vers)
117 (addToFM export_envs load_mod export_env)
123 setIfacesRn new_ifaces `thenRn_`
127 loadExport :: ExportItem -> RnMG [AvailInfo]
128 loadExport (mod, entities)
129 = mapRn load_entity entities
131 new_name occ = newGlobalName mod occ
133 -- The communcation between this little code fragment and the "entity" rule
134 -- in ParseIface.y is a bit gruesome. The idea is that things which are
135 -- destined to be AvailTCs show up as (occ, [non-empty-list]), whereas
136 -- things destined to be Avails show up as (occ, [])
138 load_entity (occ, occs)
139 = new_name occ `thenRn` \ name ->
141 returnRn (Avail name)
143 mapRn new_name occs `thenRn` \ names ->
144 returnRn (AvailTC name names)
146 loadDecl :: Module -> DeclsMap
147 -> (Version, RdrNameHsDecl)
149 loadDecl mod decls_map (version, decl)
150 = getDeclBinders new_implicit_name decl `thenRn` \ avail ->
151 returnRn (addListToFM decls_map
152 [(name,(version,avail,decl)) | name <- availNames avail]
155 new_implicit_name rdr_name loc = newGlobalName mod (rdrNameOcc rdr_name)
157 loadInstDecl :: Module
160 -> RnMG (Bag IfaceInst)
161 loadInstDecl mod_name insts decl@(InstDecl inst_ty binds uprags dfun_name src_loc)
163 -- Find out what type constructors and classes are "gates" for the
164 -- instance declaration. If all these "gates" are slurped in then
165 -- we should slurp the instance decl too.
167 -- We *don't* want to count names in the context part as gates, though.
169 -- instance Foo a => Baz (T a) where ...
171 -- Here the gates are Baz and T, but *not* Foo.
173 munged_inst_ty = case inst_ty of
174 HsForAllTy tvs cxt ty -> HsForAllTy tvs [] ty
175 HsPreForAllTy cxt ty -> HsPreForAllTy [] ty
178 -- We find the gates by renaming the instance type with in a
179 -- and returning the occurrence pool.
180 initRnMS emptyRnEnv mod_name InterfaceMode (
181 findOccurrencesRn (rnHsType munged_inst_ty)
182 ) `thenRn` \ gate_names ->
183 returnRn (((mod_name, decl), gate_names) `consBag` insts)
187 %********************************************************
189 \subsection{Loading usage information}
191 %********************************************************
194 checkUpToDate :: Module -> RnMG Bool -- True <=> no need to recompile
195 checkUpToDate mod_name
196 = findAndReadIface doc_str mod_name `thenRn` \ read_result ->
198 Nothing -> -- Old interface file not found, so we'd better bail out
199 traceRn (ppSep [ppPStr SLIT("Didnt find old iface"),
200 pprModule PprDebug mod_name]) `thenRn_`
203 Just (ParsedIface _ _ usages _ _ _ _ _)
204 -> -- Found it, so now check it
207 -- Only look in current directory, with suffix .hi
208 doc_str = ppSep [ppPStr SLIT("Need usage info from"), pprModule PprDebug mod_name]
211 checkModUsage [] = returnRn True -- Yes! Everything is up to date!
213 checkModUsage ((mod, old_mod_vers, old_local_vers) : rest)
214 = loadInterface doc_str mod `thenRn` \ ifaces ->
216 Ifaces _ mod_vers _ decls _ _ _ _ = ifaces
217 maybe_new_mod_vers = lookupFM mod_vers mod
218 Just new_mod_vers = maybe_new_mod_vers
220 -- If we can't find a version number for the old module then
221 -- bail out saying things aren't up to date
222 if not (maybeToBool maybe_new_mod_vers) then
226 -- If the module version hasn't changed, just move on
227 if new_mod_vers == old_mod_vers then
228 traceRn (ppSep [ppPStr SLIT("Module version unchanged:"), pprModule PprDebug mod]) `thenRn_`
231 traceRn (ppSep [ppPStr SLIT("Module version has changed:"), pprModule PprDebug mod]) `thenRn_`
233 -- New module version, so check entities inside
234 checkEntityUsage mod decls old_local_vers `thenRn` \ up_to_date ->
236 traceRn (ppPStr SLIT("...but the bits I use haven't.")) `thenRn_`
237 checkModUsage rest -- This one's ok, so check the rest
239 returnRn False -- This one failed, so just bail out now
241 doc_str = ppSep [ppPStr SLIT("need version info for"), pprModule PprDebug mod]
244 checkEntityUsage mod decls []
245 = returnRn True -- Yes! All up to date!
247 checkEntityUsage mod decls ((occ_name,old_vers) : rest)
248 = newGlobalName mod occ_name `thenRn` \ name ->
249 case lookupFM decls name of
251 Nothing -> -- We used it before, but it ain't there now
252 traceRn (ppSep [ppPStr SLIT("...and this no longer exported:"), ppr PprDebug name]) `thenRn_`
255 Just (new_vers,_,_) -- It's there, but is it up to date?
256 | new_vers == old_vers
257 -- Up to date, so check the rest
258 -> checkEntityUsage mod decls rest
261 -- Out of date, so bale out
262 -> traceRn (ppSep [ppPStr SLIT("...and this is out of date:"), ppr PprDebug name]) `thenRn_`
267 %*********************************************************
269 \subsection{Getting in a declaration}
271 %*********************************************************
274 importDecl :: Name -> Necessity -> RnMG (Maybe RdrNameHsDecl)
275 -- Returns Nothing for a wired-in or already-slurped decl
277 importDecl name necessity
278 = checkSlurped name `thenRn` \ already_slurped ->
279 if already_slurped then
280 -- traceRn (ppSep [ppStr "Already slurped:", ppr PprDebug name]) `thenRn_`
281 returnRn Nothing -- Already dealt with
283 if isWiredInName name then
286 getIfacesRn `thenRn` \ ifaces ->
288 Ifaces this_mod _ _ _ _ _ _ _ = ifaces
289 (mod,_) = modAndOcc name
291 if mod == this_mod then -- Don't bring in decls from
292 pprTrace "importDecl wierdness:" (ppr PprDebug name) $
293 returnRn Nothing -- the renamed module's own interface file
296 getNonWiredInDecl name necessity
301 getNonWiredInDecl :: Name -> Necessity -> RnMG (Maybe RdrNameHsDecl)
302 getNonWiredInDecl name necessity
303 = traceRn doc_str `thenRn_`
304 loadInterface doc_str mod `thenRn` \ (Ifaces _ _ _ decls _ _ _ _) ->
305 case lookupFM decls name of
307 Just (version,avail,decl) -> recordSlurp (Just version) avail `thenRn_`
310 Nothing -> -- Can happen legitimately for "Optional" occurrences
312 Optional -> addWarnRn (getDeclWarn name);
313 other -> addErrRn (getDeclErr name)
317 doc_str = ppSep [ppPStr SLIT("Need decl for"), ppr PprDebug name]
318 (mod,_) = modAndOcc name
321 @getWiredInDecl@ maps a wired-in @Name@ to what it makes available.
322 It behaves exactly as if the wired in decl were actually in an interface file.
325 * if the wired-in name is a data type constructor or a data constructor,
326 it brings in the type constructor and all the data constructors; and
327 marks as "occurrences" any free vars of the data con.
329 * similarly for synonum type constructor
331 * if the wired-in name is another wired-in Id, it marks as "occurrences"
332 the free vars of the Id's type.
334 * it loads the interface file for the wired-in thing for the
335 sole purpose of making sure that its instance declarations are available
337 All this is necessary so that we know all types that are "in play", so
338 that we know just what instances to bring into scope.
342 = get_wired `thenRn` \ avail ->
343 recordSlurp Nothing avail `thenRn_`
345 -- Force in the home module in case it has instance decls for
346 -- the thing we are interested in.
348 -- Mini hack 1: no point for non-tycons/class; and if we
349 -- do this we find PrelNum trying to import PackedString,
350 -- because PrelBase's .hi file mentions PackedString.unpackString
351 -- But PackedString.hi isn't built by that point!
353 -- Mini hack 2; GHC is guaranteed not to have
354 -- instance decls, so it's a waste of time to read it
356 -- NB: We *must* look at the availName of the slurped avail,
357 -- not the name passed to getWiredInDecl! Why? Because if a data constructor
358 -- or class op is passed to getWiredInDecl we'll pull in the whole data/class
359 -- decl, and recordSlurp will record that fact. But since the data constructor
360 -- isn't a tycon/class we won't force in the home module. And even if the
361 -- type constructor/class comes along later, loadDecl will say that it's already
362 -- been slurped, so getWiredInDecl won't even be called. Pretty obscure bug, this was.
364 main_name = availName avail
365 main_is_tc = case avail of { AvailTC _ _ -> True; Avail _ -> False }
366 (mod,_) = modAndOcc main_name
367 doc_str = ppSep [ppPStr SLIT("Need home module for wired in thing"), ppr PprDebug name]
369 (if not main_is_tc || mod == gHC__ then
372 loadInterface doc_str mod `thenRn_`
376 returnRn Nothing -- No declaration to process further
379 get_wired | is_tycon -- ... a type constructor
380 = get_wired_tycon the_tycon
382 | (isDataCon the_id) -- ... a wired-in data constructor
383 = get_wired_tycon (dataConTyCon the_id)
385 | otherwise -- ... a wired-in non data-constructor
386 = get_wired_id the_id
388 maybe_wired_in_tycon = maybeWiredInTyConName name
389 is_tycon = maybeToBool maybe_wired_in_tycon
390 maybe_wired_in_id = maybeWiredInIdName name
391 Just the_tycon = maybe_wired_in_tycon
392 Just the_id = maybe_wired_in_id
396 = addImplicitOccsRn (nameSetToList id_mentioned) `thenRn_`
397 returnRn (Avail (getName id))
399 id_mentioned = namesOfType (idType id)
401 get_wired_tycon tycon
403 = addImplicitOccsRn (nameSetToList mentioned) `thenRn_`
404 returnRn (Avail (getName tycon))
406 (tyvars,ty) = getSynTyConDefn tycon
407 mentioned = namesOfType ty `minusNameSet` mkNameSet (map getName tyvars)
409 get_wired_tycon tycon
410 | otherwise -- data or newtype
411 = addImplicitOccsRn (nameSetToList mentioned) `thenRn_`
412 returnRn (AvailTC tycon_name (tycon_name : map getName data_cons))
414 tycon_name = getName tycon
415 data_cons = tyConDataCons tycon
416 mentioned = foldr (unionNameSets . namesOfType . idType) emptyNameSet data_cons
422 = getIfacesRn `thenRn` \ (Ifaces _ _ _ _ slurped_names _ _ _) ->
423 returnRn (name `elemNameSet` slurped_names)
425 recordSlurp maybe_version avail
426 = -- traceRn (ppSep [ppStr "Record slurp:", pprAvail PprDebug avail]) `thenRn_`
427 getIfacesRn `thenRn` \ ifaces ->
429 Ifaces this_mod mod_vers export_envs decls slurped_names imp_names insts inst_mods = ifaces
430 new_slurped_names = addAvailToNameSet slurped_names avail
432 new_imp_names = case maybe_version of
433 Just version -> (availName avail, version) : imp_names
436 new_ifaces = Ifaces this_mod mod_vers export_envs decls
442 setIfacesRn new_ifaces
445 %*********************************************************
447 \subsection{Getting other stuff}
449 %*********************************************************
452 getInterfaceExports :: Module -> RnMG (Avails, [(OccName,Fixity)])
453 getInterfaceExports mod
454 = loadInterface doc_str mod `thenRn` \ (Ifaces _ _ export_envs _ _ _ _ _) ->
455 case lookupFM export_envs mod of
456 Nothing -> -- Not there; it must be that the interface file wasn't found;
457 -- the error will have been reported already.
458 -- (Actually loadInterface should put the empty export env in there
459 -- anyway, but this does no harm.)
462 Just stuff -> returnRn stuff
464 doc_str = ppSep [pprModule PprDebug mod, ppPStr SLIT("is directly imported")]
467 getImportedInstDecls :: RnMG [(Module,RdrNameInstDecl)]
469 = -- First load any special-instance modules that aren't aready loaded
470 getSpecialInstModules `thenRn` \ inst_mods ->
471 mapRn load_it inst_mods `thenRn_`
473 -- Now we're ready to grab the instance declarations
474 -- Find the un-gated ones and return them,
475 -- removing them from the bag kept in Ifaces
476 getIfacesRn `thenRn` \ ifaces ->
478 Ifaces this_mod mod_vers export_envs decls slurped_names imp_names insts inst_mods = ifaces
480 -- An instance decl is ungated if all its gates have been slurped
481 select_ungated :: IfaceInst -- A gated inst decl
483 -> ([(Module, RdrNameInstDecl)], [IfaceInst]) -- Accumulator
485 -> ([(Module, RdrNameInstDecl)], -- The ungated ones
486 [IfaceInst]) -- Still gated, but with
488 select_ungated (decl,gates) (ungated_decls, gated_decls)
489 | null remaining_gates
490 = (decl : ungated_decls, gated_decls)
492 = (ungated_decls, (decl, remaining_gates) : gated_decls)
494 remaining_gates = filter (not . (`elemNameSet` slurped_names)) gates
496 (un_gated_insts, still_gated_insts) = foldrBag select_ungated ([], []) insts
498 new_ifaces = Ifaces this_mod mod_vers export_envs decls slurped_names imp_names
499 (listToBag still_gated_insts)
502 setIfacesRn new_ifaces `thenRn_`
503 returnRn un_gated_insts
505 load_it mod = loadInterface (doc_str mod) mod
506 doc_str mod = ppSep [pprModule PprDebug mod, ppPStr SLIT("is a special-instance module")]
509 getSpecialInstModules :: RnMG [Module]
510 getSpecialInstModules
511 = getIfacesRn `thenRn` \ ifaces ->
513 Ifaces _ _ _ _ _ _ _ inst_mods = ifaces
518 getImportVersions figures out what the "usage information" for this moudule is;
519 that is, what it must record in its interface file as the things it uses.
521 - anything reachable from its body code
522 - any module exported with a "module Foo".
524 Why the latter? Because if Foo changes then this module's export list
525 will change, so we must recompile this module at least as far as
526 making a new interface file --- but in practice that means complete
530 module A( f, g ) where module B( f ) where
531 import B( f ) f = h 3
534 Should we record B.f in A's usages? In fact we don't. Certainly, if
535 anything about B.f changes than anyone who imports A should be recompiled;
536 they'll get an early exit if they don't use B.f. However, even if B.f
537 doesn't change at all, B.h may do so, and this change may not be reflected
538 in f's version number. So there are two things going on when compiling module A:
540 1. Are A.o and A.hi correct? Then we can bale out early.
541 2. Should modules that import A be recompiled?
543 For (1) it is slightly harmful to record B.f in A's usages, because a change in
544 B.f's version will provoke full recompilation of A, producing an identical A.o,
545 and A.hi differing only in its usage-version of B.f (which isn't used by any importer).
547 For (2), because of the tricky B.h question above, we ensure that A.hi is touched
548 (even if identical to its previous version) if A's recompilation was triggered by
549 an imported .hi file date change. Given that, there's no need to record B.f in
552 On the other hand, if A exports "module B" then we *do* count module B among
553 A's usages, because we must recompile A to ensure that A.hi changes appropriately.
556 getImportVersions :: Module -- Name of this module
557 -> Maybe [IE any] -- Export list for this module
558 -> RnMG (VersionInfo Name) -- Version info for these names
560 getImportVersions this_mod exports
561 = getIfacesRn `thenRn` \ ifaces ->
563 Ifaces _ mod_versions_map _ _ _ imp_names _ _ = ifaces
564 mod_version mod = expectJust "import_versions" (lookupFM mod_versions_map mod)
566 -- mv_map groups together all the things imported from a particular module.
567 mv_map, mv_map_mod :: FiniteMap Module [LocalVersion Name]
569 mv_map_mod = foldl add_mod emptyFM export_mods
570 -- mv_map_mod records all the modules that have a "module M"
571 -- in this module's export list
573 mv_map = foldl add_mv mv_map_mod imp_names
574 -- mv_map adds the version numbers of things exported individually
576 returnRn [ (mod, mod_version mod, local_versions)
577 | (mod, local_versions) <- fmToList mv_map
581 export_mods = case exports of
583 Just es -> [mod | IEModuleContents mod <- es, mod /= this_mod]
585 add_mv mv_map v@(name, version)
586 = addToFM_C (\ ls _ -> (v:ls)) mv_map mod [v]
588 (mod,_) = modAndOcc name
590 add_mod mv_map mod = addToFM mv_map mod []
593 %*********************************************************
595 \subsection{Getting binders out of a declaration}
597 %*********************************************************
599 @getDeclBinders@ returns the names for a @RdrNameHsDecl@.
600 It's used for both source code (from @availsFromDecl@) and interface files
603 It doesn't deal with source-code specific things: ValD, DefD. They
604 are handled by the sourc-code specific stuff in RnNames.
607 getDeclBinders :: (RdrName -> SrcLoc -> RnMG Name) -- New-name function
611 getDeclBinders new_name (TyD (TyData _ tycon _ condecls _ _ src_loc))
612 = new_name tycon src_loc `thenRn` \ tycon_name ->
613 getConFieldNames new_name condecls `thenRn` \ sub_names ->
614 returnRn (AvailTC tycon_name (tycon_name : sub_names))
616 getDeclBinders new_name (TyD (TyNew _ tycon _ (NewConDecl con _ con_loc) _ _ src_loc))
617 = new_name tycon src_loc `thenRn` \ tycon_name ->
618 new_name con src_loc `thenRn` \ con_name ->
619 returnRn (AvailTC tycon_name [tycon_name, con_name])
621 getDeclBinders new_name (TyD (TySynonym tycon _ _ src_loc))
622 = new_name tycon src_loc `thenRn` \ tycon_name ->
623 returnRn (Avail tycon_name)
625 getDeclBinders new_name (ClD (ClassDecl _ cname _ sigs _ _ src_loc))
626 = new_name cname src_loc `thenRn` \ class_name ->
627 mapRn (getClassOpNames new_name) sigs `thenRn` \ sub_names ->
628 returnRn (AvailTC class_name (class_name : sub_names))
630 getDeclBinders new_name (SigD (IfaceSig var ty prags src_loc))
631 = new_name var src_loc `thenRn` \ var_name ->
632 returnRn (Avail var_name)
634 getDeclBinders new_name (DefD _) = returnRn NotAvailable
635 getDeclBinders new_name (InstD _) = returnRn NotAvailable
638 getConFieldNames new_name (ConDecl con _ src_loc : rest)
639 = new_name con src_loc `thenRn` \ n ->
640 getConFieldNames new_name rest `thenRn` \ ns ->
643 getConFieldNames new_name (NewConDecl con _ src_loc : rest)
644 = new_name con src_loc `thenRn` \ n ->
645 getConFieldNames new_name rest `thenRn` \ ns ->
648 getConFieldNames new_name (ConOpDecl _ con _ src_loc : rest)
649 = new_name con src_loc `thenRn` \ n ->
650 getConFieldNames new_name rest `thenRn` \ ns ->
653 getConFieldNames new_name (RecConDecl con fielddecls src_loc : rest)
654 = mapRn (\n -> new_name n src_loc) (con:fields) `thenRn` \ cfs ->
655 getConFieldNames new_name rest `thenRn` \ ns ->
658 fields = concat (map fst fielddecls)
660 getConFieldNames new_name [] = returnRn []
662 getClassOpNames new_name (ClassOpSig op _ _ src_loc) = new_name op src_loc
666 %*********************************************************
668 \subsection{Reading an interface file}
670 %*********************************************************
673 findAndReadIface :: Pretty -> Module -> RnMG (Maybe ParsedIface)
674 -- Nothing <=> file not found, or unreadable, or illegible
675 -- Just x <=> successfully found and parsed
676 findAndReadIface doc_str mod
677 = traceRn trace_msg `thenRn_`
678 getSearchPathRn `thenRn` \ dirs ->
681 trace_msg = ppHang (ppBesides [ppPStr SLIT("Reading interface for "),
682 pprModule PprDebug mod, ppSemi])
683 4 (ppBesides [ppPStr SLIT("reason: "), doc_str])
685 mod_str = moduleString mod
687 if isPreludeModule mod then
688 case opt_HiSuffixPrelude of { Just hisuf -> hisuf; _ -> ".hi"}
690 case opt_HiSuffix of {Just hisuf -> hisuf; _ -> ".hi"}
692 try all_dirs [] = traceRn (ppPStr SLIT("...failed")) `thenRn_`
695 try all_dirs (dir:dirs)
696 = readIface file_path `thenRn` \ read_result ->
698 Nothing -> try all_dirs dirs
699 Just iface -> traceRn (ppPStr SLIT("...done")) `thenRn_`
700 returnRn (Just iface)
702 file_path = dir ++ "/" ++ moduleString mod ++ hisuf
705 @readIface@ trys just one file.
708 readIface :: String -> RnMG (Maybe ParsedIface)
709 -- Nothing <=> file not found, or unreadable, or illegible
710 -- Just x <=> successfully found and parsed
712 = ioToRnMG (hGetStringBuffer file_path) `thenRn` \ read_result ->
713 --OLD: = ioToRnMG (readFile file_path) `thenRn` \ read_result ->
715 Right contents -> case parseIface contents of
716 Failed err -> --ioToRnMG (freeStringBuffer contents) `thenRn` \ _ ->
717 failWithRn Nothing err
718 Succeeded iface -> --ioToRnMG (freeStringBuffer contents) `thenRn` \ _ ->
719 returnRn (Just iface)
721 Left (NoSuchThing _) -> returnRn Nothing
723 Left err -> failWithRn Nothing
724 (cannaeReadFile file_path err)
728 mkSearchPath takes a string consisting of a colon-separated list of directories, and turns it into
729 a list of directories. For example:
731 mkSearchPath "foo:.:baz" = ["foo", ".", "baz"]
734 mkSearchPath :: Maybe String -> SearchPath
735 mkSearchPath Nothing = ["."]
736 mkSearchPath (Just s)
740 go s = first : go (drop 1 rest)
742 (first,rest) = span (/= ':') s
745 %*********************************************************
749 %*********************************************************
753 = ppBesides [ppPStr SLIT("Could not find valid interface file for "), ppQuote (pprModule sty mod)]
754 -- , ppStr " in"]) 4 (ppAboves (map ppStr dirs))
756 cannaeReadFile file err sty
757 = ppBesides [ppPStr SLIT("Failed in reading file: "), ppStr file, ppPStr SLIT("; error="), ppStr (show err)]
760 = ppSep [ppPStr SLIT("Failed to find interface decl for"), ppr sty name]
763 = ppSep [ppPStr SLIT("Warning: failed to find (optional) interface decl for"), ppr sty name]