[project @ 2002-01-23 11:11:13 by simonmar]
[ghc-hetmet.git] / ghc / compiler / compMan / CompManager.lhs
1 %
2 % (c) The University of Glasgow, 2002
3 %
4 % The Compilation Manager
5 %
6 \begin{code}
7 {-# OPTIONS -fvia-C #-}
8 module CompManager ( 
9     ModuleGraph, 
10
11     CmState, emptyCmState,  -- abstract
12
13     cmInit,        -- :: GhciMode -> IO CmState
14
15     cmDepAnal,     -- :: CmState -> DynFlags -> [FilePath] -> IO ModuleGraph
16
17     cmLoadModules, -- :: CmState -> DynFlags -> ModuleGraph
18                    --    -> IO (CmState, [String])
19
20     cmUnload,      -- :: CmState -> DynFlags -> IO CmState
21
22 #ifdef GHCI
23     cmModuleIsInterpreted, -- :: CmState -> String -> IO Bool
24
25     cmSetContext,  -- :: CmState -> DynFlags -> [String] -> [String] -> IO CmState
26     cmGetContext,  -- :: CmState -> IO ([String],[String])
27
28     cmInfoThing,   -- :: CmState -> DynFlags -> String -> IO (Maybe TyThing)
29
30     CmRunResult(..),
31     cmRunStmt,     -- :: CmState -> DynFlags -> String
32                    --    -> IO (CmState, CmRunResult)
33
34     cmTypeOfExpr,  -- :: CmState -> DynFlags -> String
35                    --   -> IO (CmState, Maybe String)
36
37     cmTypeOfName,  -- :: CmState -> Name -> IO (Maybe String)
38
39     HValue,
40     cmCompileExpr, -- :: CmState -> DynFlags -> String 
41                    --   -> IO (CmState, Maybe HValue)
42 #endif
43   )
44 where
45
46 #include "HsVersions.h"
47
48 import CmLink
49 import CmTypes
50 import DriverPipeline
51 import DriverState      ( v_Output_file )
52 import DriverPhases
53 import DriverUtil
54 import Finder
55 #ifdef GHCI
56 import HscMain          ( initPersistentCompilerState, hscThing )
57 #else
58 import HscMain          ( initPersistentCompilerState )
59 #endif
60 import HscTypes
61 import Name             ( Name, NamedThing(..), nameRdrName, nameModule,
62                           isHomePackageName )
63 import Rename           ( mkGlobalContext )
64 import RdrName          ( emptyRdrEnv )
65 import Module
66 import GetImports
67 import UniqFM
68 import Unique           ( Uniquable )
69 import Digraph          ( SCC(..), stronglyConnComp, flattenSCC, flattenSCCs )
70 import ErrUtils         ( showPass )
71 import SysTools         ( cleanTempFilesExcept )
72 import Util
73 import Outputable
74 import Panic
75 import CmdLineOpts      ( DynFlags(..), getDynFlags )
76
77 import IOExts
78
79 #ifdef GHCI
80 import RdrName          ( lookupRdrEnv )
81 import Id               ( idType, idName )
82 import NameEnv
83 import Type             ( tidyType )
84 import VarEnv           ( emptyTidyEnv )
85 import BasicTypes       ( Fixity, defaultFixity )
86 import Interpreter      ( HValue )
87 import HscMain          ( hscStmt )
88 import PrelGHC          ( unsafeCoerce# )
89
90 import Foreign
91 import CForeign
92 import Exception        ( Exception, try )
93 #endif
94
95 -- lang
96 import Exception        ( throwDyn )
97
98 -- std
99 import Directory        ( getModificationTime, doesFileExist )
100 import IO
101 import Monad
102 import List             ( nub )
103 import Maybe
104 \end{code}
105
106
107 \begin{code}
108 -- Persistent state for the entire system
109 data CmState
110    = CmState {
111         hst   :: HomeSymbolTable,    -- home symbol table
112         hit   :: HomeIfaceTable,     -- home interface table
113         ui    :: UnlinkedImage,      -- the unlinked images
114         mg    :: ModuleGraph,        -- the module graph
115         gmode :: GhciMode,           -- NEVER CHANGES
116         ic    :: InteractiveContext, -- command-line binding info
117
118         pcs    :: PersistentCompilerState, -- compile's persistent state
119         pls    :: PersistentLinkerState    -- link's persistent state
120      }
121
122 emptyCmState :: GhciMode -> IO CmState
123 emptyCmState gmode
124     = do pcs     <- initPersistentCompilerState
125          pls     <- emptyPLS
126          return (CmState { hst    = emptySymbolTable,
127                            hit    = emptyIfaceTable,
128                            ui     = emptyUI,
129                            mg     = emptyMG, 
130                            gmode  = gmode,
131                            ic     = emptyInteractiveContext,
132                            pcs    = pcs,
133                            pls    = pls })
134
135 emptyInteractiveContext
136   = InteractiveContext { ic_toplev_scope = [],
137                          ic_exports = [],
138                          ic_rn_gbl_env = emptyRdrEnv,
139                          ic_print_unqual = alwaysQualify,
140                          ic_rn_local_env = emptyRdrEnv,
141                          ic_type_env = emptyTypeEnv }
142
143 -- CM internal types
144 type UnlinkedImage = [Linkable] -- the unlinked images (should be a set, really)
145 emptyUI :: UnlinkedImage
146 emptyUI = []
147
148 type ModuleGraph = [ModSummary]  -- the module graph, topologically sorted
149 emptyMG :: ModuleGraph
150 emptyMG = []
151
152 -----------------------------------------------------------------------------
153 -- Produce an initial CmState.
154
155 cmInit :: GhciMode -> IO CmState
156 cmInit mode = emptyCmState mode
157
158 -----------------------------------------------------------------------------
159 -- Setting the context doesn't throw away any bindings; the bindings
160 -- we've built up in the InteractiveContext simply move to the new
161 -- module.  They always shadow anything in scope in the current context.
162
163 cmSetContext
164         :: CmState -> DynFlags
165         -> [String]             -- take the top-level scopes of these modules
166         -> [String]             -- and the just the exports from these
167         -> IO CmState
168 cmSetContext cmstate dflags toplevs exports = do 
169   let CmState{ hit=hit, hst=hst, pcs=pcs, ic=old_ic } = cmstate
170
171   toplev_mods <- mapM (getTopLevModule hit)    (map mkModuleName toplevs)
172   export_mods <- mapM (moduleNameToModule hit) (map mkModuleName exports)
173
174   (new_pcs, print_unqual, maybe_env)
175       <- mkGlobalContext dflags hit hst pcs toplev_mods export_mods
176
177   case maybe_env of 
178     Nothing -> return cmstate
179     Just env -> return cmstate{ pcs = new_pcs,
180                                 ic = old_ic{ ic_toplev_scope = toplev_mods,
181                                              ic_exports = export_mods,
182                                              ic_rn_gbl_env = env,
183                                              ic_print_unqual = print_unqual } }
184
185 getTopLevModule hit mn =
186   case lookupModuleEnvByName hit mn of
187     Just iface
188       | Just _ <- mi_globals iface -> return (mi_module iface)
189     _other -> throwDyn (CmdLineError (
190           "cannot enter the top-level scope of a compiled module (module `" ++
191            moduleNameUserString mn ++ "')"))
192
193 moduleNameToModule :: HomeIfaceTable -> ModuleName -> IO Module
194 moduleNameToModule hit mn = do
195   case lookupModuleEnvByName hit mn of
196     Just iface -> return (mi_module iface)
197     _not_a_home_module -> do
198         maybe_stuff <- findModule mn
199         case maybe_stuff of
200           Nothing -> throwDyn (CmdLineError ("can't find module `"
201                                     ++ moduleNameUserString mn ++ "'"))
202           Just (m,_) -> return m
203
204 cmGetContext :: CmState -> IO ([String],[String])
205 cmGetContext CmState{ic=ic} = 
206   return (map moduleUserString (ic_toplev_scope ic), 
207           map moduleUserString (ic_exports ic))
208
209 cmModuleIsInterpreted :: CmState -> String -> IO Bool
210 cmModuleIsInterpreted cmstate str 
211  = case lookupModuleEnvByName (hit cmstate) (mkModuleName str) of
212       Just iface         -> return (not (isNothing (mi_globals iface)))
213       _not_a_home_module -> return False
214
215 -----------------------------------------------------------------------------
216 -- cmInfoThing: convert a String to a TyThing
217
218 -- A string may refer to more than one TyThing (eg. a constructor,
219 -- and type constructor), so we return a list of all the possible TyThings.
220
221 #ifdef GHCI
222 cmInfoThing :: CmState -> DynFlags -> String 
223         -> IO (CmState, PrintUnqualified, [(TyThing,Fixity)])
224 cmInfoThing cmstate dflags id
225    = do (new_pcs, things) <- hscThing dflags hst hit pcs icontext id
226         let pairs = map (\x -> (x, getFixity new_pcs (getName x))) things
227         return (cmstate{ pcs=new_pcs }, unqual, pairs)
228    where 
229      CmState{ hst=hst, hit=hit, pcs=pcs, pls=pls, ic=icontext } = cmstate
230      unqual = ic_print_unqual icontext
231
232      getFixity :: PersistentCompilerState -> Name -> Fixity
233      getFixity pcs name
234         | Just iface  <- lookupModuleEnv iface_table (nameModule name),
235           Just fixity <- lookupNameEnv (mi_fixities iface) name
236           = fixity
237         | otherwise
238           = defaultFixity
239         where iface_table | isHomePackageName name = hit
240                           | otherwise              = pcs_PIT pcs
241 #endif
242
243 -----------------------------------------------------------------------------
244 -- cmRunStmt:  Run a statement/expr.
245
246 #ifdef GHCI
247 data CmRunResult
248   = CmRunOk [Name]              -- names bound by this evaluation
249   | CmRunFailed 
250   | CmRunException Exception    -- statement raised an exception
251
252 cmRunStmt :: CmState -> DynFlags -> String -> IO (CmState, CmRunResult)         
253 cmRunStmt cmstate@CmState{ hst=hst, hit=hit, pcs=pcs, pls=pls, ic=icontext }
254           dflags expr
255    = do 
256         let InteractiveContext { 
257                 ic_rn_local_env = rn_env, 
258                 ic_type_env     = type_env } = icontext
259
260         (new_pcs, maybe_stuff) 
261             <- hscStmt dflags hst hit pcs icontext expr False{-stmt-}
262
263         case maybe_stuff of
264            Nothing -> return (cmstate{ pcs=new_pcs }, CmRunFailed)
265            Just (ids, _, bcos) -> do
266
267                 -- update the interactive context
268                 let 
269                     names = map idName ids
270
271                     -- these names have just been shadowed
272                     shadowed = [ n | r <- map nameRdrName names,
273                                      Just n <- [lookupRdrEnv rn_env r] ]
274                     
275                     new_rn_env   = extendLocalRdrEnv rn_env names
276
277                     -- remove any shadowed bindings from the type_env
278                     filtered_type_env = delListFromNameEnv type_env shadowed
279
280                     new_type_env = extendNameEnvList filtered_type_env  
281                                         [ (getName id, AnId id) | id <- ids]
282
283                     new_ic = icontext { ic_rn_local_env = new_rn_env, 
284                                         ic_type_env     = new_type_env }
285
286                 -- link it
287                 hval <- linkExpr pls bcos
288
289                 -- run it!
290                 let thing_to_run = unsafeCoerce# hval :: IO [HValue]
291                 either_hvals <- sandboxIO thing_to_run
292                 case either_hvals of
293                    Left err
294                         -> do hPutStrLn stderr ("unknown failure, code " ++ show err)
295                               return ( cmstate{ pcs=new_pcs, ic=new_ic }, CmRunFailed )
296
297                    Right maybe_hvals ->
298                      case maybe_hvals of
299                         Left e -> 
300                             return ( cmstate{ pcs=new_pcs, ic=new_ic }, 
301                                      CmRunException e )
302                         Right hvals -> do
303                              -- Get the newly bound things, and bind them.  
304                              -- Don't forget to delete any shadowed bindings from the
305                              -- closure_env, lest we end up with a space leak.
306                              pls <- delListFromClosureEnv pls shadowed
307                              new_pls <- addListToClosureEnv pls (zip names hvals)
308              
309                              return (cmstate{ pcs=new_pcs, pls=new_pls, ic=new_ic }, 
310                                      CmRunOk names)
311
312
313 -- We run the statement in a "sandbox" to protect the rest of the
314 -- system from anything the expression might do.  For now, this
315 -- consists of just wrapping it in an exception handler, but see below
316 -- for another version.
317
318 sandboxIO :: IO a -> IO (Either Int (Either Exception a))
319 sandboxIO thing = do
320   r <- Exception.try thing
321   return (Right r)
322
323 {-
324 -- This version of sandboxIO runs the expression in a completely new
325 -- RTS main thread.  It is disabled for now because ^C exceptions
326 -- won't be delivered to the new thread, instead they'll be delivered
327 -- to the (blocked) GHCi main thread.
328
329 sandboxIO :: IO a -> IO (Either Int (Either Exception a))
330 sandboxIO thing = do
331   st_thing <- newStablePtr (Exception.try thing)
332   alloca $ \ p_st_result -> do
333     stat <- rts_evalStableIO st_thing p_st_result
334     freeStablePtr st_thing
335     if stat == 1
336         then do st_result <- peek p_st_result
337                 result <- deRefStablePtr st_result
338                 freeStablePtr st_result
339                 return (Right result)
340         else do
341                 return (Left (fromIntegral stat))
342
343 foreign import "rts_evalStableIO"  {- safe -}
344   rts_evalStableIO :: StablePtr (IO a) -> Ptr (StablePtr a) -> IO CInt
345   -- more informative than the C type!
346 -}
347 #endif
348
349 -----------------------------------------------------------------------------
350 -- cmTypeOfExpr: returns a string representing the type of an expression
351
352 #ifdef GHCI
353 cmTypeOfExpr :: CmState -> DynFlags -> String -> IO (CmState, Maybe String)
354 cmTypeOfExpr cmstate dflags expr
355    = do (new_pcs, maybe_stuff) 
356           <- hscStmt dflags hst hit pcs ic expr True{-just an expr-}
357
358         let new_cmstate = cmstate{pcs = new_pcs}
359
360         case maybe_stuff of
361            Nothing -> return (new_cmstate, Nothing)
362            Just (_, ty, _) -> return (new_cmstate, Just str)
363              where 
364                 str = showSDocForUser unqual (ppr tidy_ty)
365                 unqual  = ic_print_unqual ic
366                 tidy_ty = tidyType emptyTidyEnv ty
367    where
368        CmState{ hst=hst, hit=hit, pcs=pcs, ic=ic } = cmstate
369 #endif
370
371 -----------------------------------------------------------------------------
372 -- cmTypeOfName: returns a string representing the type of a name.
373
374 #ifdef GHCI
375 cmTypeOfName :: CmState -> Name -> IO (Maybe String)
376 cmTypeOfName CmState{ hit=hit, pcs=pcs, ic=ic } name
377  = case lookupNameEnv (ic_type_env ic) name of
378         Nothing -> return Nothing
379         Just (AnId id) -> return (Just str)
380            where
381              unqual = ic_print_unqual ic
382              ty = tidyType emptyTidyEnv (idType id)
383              str = showSDocForUser unqual (ppr ty)
384
385         _ -> panic "cmTypeOfName"
386 #endif
387
388 -----------------------------------------------------------------------------
389 -- cmCompileExpr: compile an expression and deliver an HValue
390
391 #ifdef GHCI
392 cmCompileExpr :: CmState -> DynFlags -> String -> IO (CmState, Maybe HValue)
393 cmCompileExpr cmstate dflags expr
394    = do 
395         let InteractiveContext { 
396                 ic_rn_local_env = rn_env, 
397                 ic_type_env     = type_env } = icontext
398
399         (new_pcs, maybe_stuff) 
400             <- hscStmt dflags hst hit pcs icontext 
401                   ("let __cmCompileExpr = "++expr) False{-stmt-}
402
403         case maybe_stuff of
404            Nothing -> return (cmstate{ pcs=new_pcs }, Nothing)
405            Just (ids, _, bcos) -> do
406
407                 -- link it
408                 hval <- linkExpr pls bcos
409
410                 -- run it!
411                 let thing_to_run = unsafeCoerce# hval :: IO [HValue]
412                 hvals <- thing_to_run
413
414                 case (ids,hvals) of
415                   ([id],[hv]) -> return (cmstate{ pcs=new_pcs }, Just hv)
416                   _ -> panic "cmCompileExpr"
417
418    where
419        CmState{ hst=hst, hit=hit, pcs=pcs, pls=pls, ic=icontext } = cmstate
420 #endif
421
422 -----------------------------------------------------------------------------
423 -- Unload the compilation manager's state: everything it knows about the
424 -- current collection of modules in the Home package.
425
426 cmUnload :: CmState -> DynFlags -> IO CmState
427 cmUnload state@CmState{ gmode=mode, pls=pls, pcs=pcs } dflags
428  = do -- Throw away the old home dir cache
429       emptyHomeDirCache
430
431       -- Unload everything the linker knows about
432       new_pls <- CmLink.unload mode dflags [] pls 
433
434       -- Start with a fresh CmState, but keep the PersistentCompilerState
435       new_state <- cmInit mode
436       return new_state{ pcs=pcs, pls=new_pls }
437
438
439 -----------------------------------------------------------------------------
440 -- Trace dependency graph
441
442 -- This is a seperate pass so that the caller can back off and keep
443 -- the current state if the downsweep fails.
444
445 cmDepAnal :: CmState -> DynFlags -> [FilePath] -> IO ModuleGraph
446 cmDepAnal cmstate dflags rootnames
447   = do showPass dflags "Chasing dependencies"
448        when (verbosity dflags >= 1 && gmode cmstate == Batch) $
449            hPutStrLn stderr (showSDoc (hcat [
450              text progName, text ": chasing modules from: ",
451              hcat (punctuate comma (map text rootnames))]))
452        downsweep rootnames (mg cmstate)
453
454 -----------------------------------------------------------------------------
455 -- The real business of the compilation manager: given a system state and
456 -- a module name, try and bring the module up to date, probably changing
457 -- the system state at the same time.
458
459 cmLoadModules :: CmState 
460              -> DynFlags
461              -> ModuleGraph
462              -> IO (CmState,            -- new state
463                     Bool,               -- was successful
464                     [String])           -- list of modules loaded
465
466 cmLoadModules cmstate1 dflags mg2unsorted
467    = do -- version 1's are the original, before downsweep
468         let pls1      = pls    cmstate1
469         let pcs1      = pcs    cmstate1
470         let hst1      = hst    cmstate1
471         let hit1      = hit    cmstate1
472         -- similarly, ui1 is the (complete) set of linkables from
473         -- the previous pass, if any.
474         let ui1       = ui     cmstate1
475
476         let ghci_mode = gmode cmstate1 -- this never changes
477
478         -- Do the downsweep to reestablish the module graph
479         let verb = verbosity dflags
480
481         -- Find out if we have a Main module
482         let a_root_is_Main 
483                = any ((=="Main").moduleNameUserString.name_of_summary) 
484                      mg2unsorted
485
486         let mg2unsorted_names = map name_of_summary mg2unsorted
487
488         -- reachable_from follows source as well as normal imports
489         let reachable_from :: ModuleName -> [ModuleName]
490             reachable_from = downwards_closure_of_module mg2unsorted
491  
492         -- should be cycle free; ignores 'import source's
493         let mg2 = topological_sort False mg2unsorted
494         -- ... whereas this takes them into account.  Used for
495         -- backing out partially complete cycles following a failed
496         -- upsweep, and for removing from hst/hit all the modules
497         -- not in strict downwards closure, during calls to compile.
498         let mg2_with_srcimps = topological_sort True mg2unsorted
499
500         -- Sort out which linkables we wish to keep in the unlinked image.
501         -- See getValidLinkables below for details.
502         valid_linkables <- getValidLinkables ui1 mg2unsorted_names 
503                                 mg2_with_srcimps
504         -- when (verb >= 2) $
505         --    putStrLn (showSDoc (text "Valid linkables:" 
506         --                       <+> ppr valid_linkables))
507
508         -- Figure out a stable set of modules which can be retained
509         -- the top level envs, to avoid upsweeping them.  Goes to a
510         -- bit of trouble to avoid upsweeping module cycles.
511         --
512         -- Construct a set S of stable modules like this:
513         -- Travel upwards, over the sccified graph.  For each scc
514         -- of modules ms, add ms to S only if:
515         -- 1.  All home imports of ms are either in ms or S
516         -- 2.  A valid linkable exists for each module in ms
517
518         stable_mods <- preUpsweep valid_linkables hit1 
519                                   mg2unsorted_names [] mg2_with_srcimps
520
521         let stable_summaries
522                = concatMap (findInSummaries mg2unsorted) stable_mods
523
524             stable_linkables
525                = filter (\m -> linkableModName m `elem` stable_mods) 
526                     valid_linkables
527
528         when (verb >= 2) $
529            putStrLn (showSDoc (text "Stable modules:" 
530                                <+> sep (map (text.moduleNameUserString) stable_mods)))
531
532         -- unload any modules which aren't going to be re-linked this
533         -- time around.
534         pls2 <- CmLink.unload ghci_mode dflags stable_linkables pls1
535
536         -- We could at this point detect cycles which aren't broken by
537         -- a source-import, and complain immediately, but it seems better
538         -- to let upsweep_mods do this, so at least some useful work gets
539         -- done before the upsweep is abandoned.
540         let upsweep_these
541                = filter (\scc -> any (`notElem` stable_mods) 
542                                      (map name_of_summary (flattenSCC scc)))
543                         mg2
544
545         --hPutStrLn stderr "after tsort:\n"
546         --hPutStrLn stderr (showSDoc (vcat (map ppr mg2)))
547
548         -- Because we don't take into account source imports when doing
549         -- the topological sort, there shouldn't be any cycles in mg2.
550         -- If there is, we complain and give up -- the user needs to
551         -- break the cycle using a boot file.
552
553         -- Now do the upsweep, calling compile for each module in
554         -- turn.  Final result is version 3 of everything.
555
556         let threaded2 = CmThreaded pcs1 hst1 hit1
557
558         -- clean up between compilations
559         let cleanup = cleanTempFilesExcept verb 
560                           (ppFilesFromSummaries (flattenSCCs upsweep_these))
561
562         (upsweep_complete_success, threaded3, modsUpswept, newLis)
563            <- upsweep_mods ghci_mode dflags valid_linkables reachable_from 
564                            threaded2 cleanup upsweep_these
565
566         let ui3 = add_to_ui valid_linkables newLis
567         let (CmThreaded pcs3 hst3 hit3) = threaded3
568
569         -- At this point, modsUpswept and newLis should have the same
570         -- length, so there is one new (or old) linkable for each 
571         -- mod which was processed (passed to compile).
572
573         -- Make modsDone be the summaries for each home module now
574         -- available; this should equal the domains of hst3 and hit3.
575         -- (NOT STRICTLY TRUE if an interactive session was started
576         --  with some object on disk ???)
577         -- Get in in a roughly top .. bottom order (hence reverse).
578
579         let modsDone = reverse modsUpswept ++ stable_summaries
580
581         -- Try and do linking in some form, depending on whether the
582         -- upsweep was completely or only partially successful.
583
584         if upsweep_complete_success
585
586          then 
587            -- Easy; just relink it all.
588            do when (verb >= 2) $ 
589                  hPutStrLn stderr "Upsweep completely successful."
590
591               -- clean up after ourselves
592               cleanTempFilesExcept verb (ppFilesFromSummaries modsDone)
593
594               -- issue a warning for the confusing case where the user said '-o foo'
595               -- but we're not going to do any linking.
596               ofile <- readIORef v_Output_file
597               when (ghci_mode == Batch && isJust ofile && not a_root_is_Main
598                      && verb > 0) $
599                  hPutStrLn stderr "Warning: output was redirected with -o, but no output will be generated\nbecause there is no Main module."
600
601               -- link everything together
602               linkresult <- link ghci_mode dflags a_root_is_Main ui3 pls2
603
604               cmLoadFinish True linkresult 
605                         hst3 hit3 ui3 modsDone ghci_mode pcs3
606
607          else 
608            -- Tricky.  We need to back out the effects of compiling any
609            -- half-done cycles, both so as to clean up the top level envs
610            -- and to avoid telling the interactive linker to link them.
611            do when (verb >= 2) $
612                 hPutStrLn stderr "Upsweep partially successful."
613
614               let modsDone_names
615                      = map name_of_summary modsDone
616               let mods_to_zap_names 
617                      = findPartiallyCompletedCycles modsDone_names 
618                           mg2_with_srcimps
619               let mods_to_keep
620                      = filter ((`notElem` mods_to_zap_names).name_of_summary) 
621                           modsDone
622
623               let (hst4, hit4, ui4)
624                      = retainInTopLevelEnvs (map name_of_summary mods_to_keep) 
625                                             (hst3,hit3,ui3)
626
627               -- clean up after ourselves
628               cleanTempFilesExcept verb (ppFilesFromSummaries mods_to_keep)
629
630               -- link everything together
631               linkresult <- link ghci_mode dflags False ui4 pls2
632
633               cmLoadFinish False linkresult 
634                     hst4 hit4 ui4 mods_to_keep ghci_mode pcs3
635
636
637 -- Finish up after a cmLoad.
638
639 -- If the link failed, unload everything and return.
640 cmLoadFinish ok (LinkFailed pls) hst hit ui mods ghci_mode pcs = do
641   dflags <- getDynFlags
642   new_pls <- CmLink.unload ghci_mode dflags [] pls 
643   new_state <- cmInit ghci_mode
644   return (new_state{ pcs=pcs, pls=new_pls }, False, [])
645
646 -- Empty the interactive context and set the module context to the topmost
647 -- newly loaded module, or the Prelude if none were loaded.
648 cmLoadFinish ok (LinkOK pls) hst hit ui mods ghci_mode pcs
649   = do let new_cmstate = CmState{ hst=hst, hit=hit, ui=ui, mg=mods,
650                                   gmode=ghci_mode, pcs=pcs, pls=pls,
651                                   ic = emptyInteractiveContext }
652            mods_loaded = map (moduleNameUserString.name_of_summary) mods
653
654        return (new_cmstate, ok, mods_loaded)
655
656 -- used to fish out the preprocess output files for the purposes
657 -- of cleaning up.
658 ppFilesFromSummaries summaries
659   = [ fn | Just fn <- map toPpFile summaries ]
660   where
661    toPpFile sum
662      | hspp /= ml_hs_file loc = hspp
663      | otherwise              = Nothing
664     where
665       loc  = ms_location sum
666       hspp = ml_hspp_file loc
667
668
669 -----------------------------------------------------------------------------
670 -- getValidLinkables
671
672 -- For each module (or SCC of modules), we take:
673 --
674 --      - an on-disk linkable, if this is the first time around and one
675 --        is available.
676 --
677 --      - the old linkable, otherwise (and if one is available).
678 --
679 -- and we throw away the linkable if it is older than the source
680 -- file.  We ignore the on-disk linkables unless all of the dependents
681 -- of this SCC also have on-disk linkables.
682 --
683 -- If a module has a valid linkable, then it may be STABLE (see below),
684 -- and it is classified as SOURCE UNCHANGED for the purposes of calling
685 -- compile.
686 --
687 -- ToDo: this pass could be merged with the preUpsweep.
688
689 getValidLinkables
690         :: [Linkable]           -- old linkables
691         -> [ModuleName]         -- all home modules
692         -> [SCC ModSummary]     -- all modules in the program, dependency order
693         -> IO [Linkable]        -- still-valid linkables 
694
695 getValidLinkables old_linkables all_home_mods module_graph
696   = foldM (getValidLinkablesSCC old_linkables all_home_mods) [] module_graph
697
698 getValidLinkablesSCC old_linkables all_home_mods new_linkables scc0
699    = let 
700           scc             = flattenSCC scc0
701           scc_names       = map name_of_summary scc
702           home_module m   = m `elem` all_home_mods && m `notElem` scc_names
703           scc_allhomeimps = nub (filter home_module (concatMap ms_imps scc))
704                 -- NOTE: ms_imps, not ms_allimps above.  We don't want to
705                 -- force a module's SOURCE imports to be already compiled for
706                 -- its object linkable to be valid.
707
708           has_object m = case findModuleLinkable_maybe new_linkables m of
709                             Nothing -> False
710                             Just l  -> isObjectLinkable l
711
712           objects_allowed = all has_object scc_allhomeimps
713      in do
714
715      these_linkables 
716         <- foldM (getValidLinkable old_linkables objects_allowed) [] scc
717
718         -- since an scc can contain only all objects or no objects at all,
719         -- we have to check whether we got all objects or not, and re-do
720         -- the linkable check if not.
721      adjusted_linkables 
722         <- if objects_allowed && not (all isObjectLinkable these_linkables)
723               then foldM (getValidLinkable old_linkables False) [] scc
724               else return these_linkables
725
726      return (adjusted_linkables ++ new_linkables)
727
728
729 getValidLinkable :: [Linkable] -> Bool -> [Linkable] -> ModSummary 
730         -> IO [Linkable]
731 getValidLinkable old_linkables objects_allowed new_linkables summary 
732   = do let mod_name = name_of_summary summary
733
734        maybe_disk_linkable
735           <- if (not objects_allowed)
736                 then return Nothing
737                 else case ml_obj_file (ms_location summary) of
738                         Just obj_fn -> maybe_getFileLinkable mod_name obj_fn
739                         Nothing -> return Nothing
740
741        let old_linkable = findModuleLinkable_maybe old_linkables mod_name
742            maybe_old_linkable =
743                 case old_linkable of
744                     Just l | not (isObjectLinkable l) || stillThere l 
745                                 -> old_linkable
746                                 -- ToDo: emit a warning if not (stillThere l)
747                     other -> Nothing
748
749            -- make sure that if we had an old disk linkable around, that it's
750            -- still there on the disk (in case we need to re-link it).
751            stillThere l = 
752                 case maybe_disk_linkable of
753                    Nothing    -> False
754                    Just l_disk -> linkableTime l == linkableTime l_disk
755
756            -- we only look for objects on disk the first time around;
757            -- if the user compiles a module on the side during a GHCi session,
758            -- it won't be picked up until the next ":load".  This is what the
759            -- "null old_linkables" test below is.
760            linkable | null old_linkables = maybeToList maybe_disk_linkable
761                     | otherwise          = maybeToList maybe_old_linkable
762
763            -- only linkables newer than the source code are valid
764            src_date = ms_hs_date summary
765
766            valid_linkable
767               =  filter (\l -> linkableTime l >= src_date) linkable
768                 -- why '>=' rather than '>' above?  If the filesystem stores
769                 -- times to the nearset second, we may occasionally find that
770                 -- the object & source have the same modification time, 
771                 -- especially if the source was automatically generated
772                 -- and compiled.  Using >= is slightly unsafe, but it matches
773                 -- make's behaviour.
774
775        return (valid_linkable ++ new_linkables)
776
777
778 maybe_getFileLinkable :: ModuleName -> FilePath -> IO (Maybe Linkable)
779 maybe_getFileLinkable mod_name obj_fn
780    = do obj_exist <- doesFileExist obj_fn
781         if not obj_exist 
782          then return Nothing 
783          else 
784          do let stub_fn = case splitFilename3 obj_fn of
785                              (dir, base, ext) -> dir ++ "/" ++ base ++ ".stub_o"
786             stub_exist <- doesFileExist stub_fn
787             obj_time <- getModificationTime obj_fn
788             if stub_exist
789              then return (Just (LM obj_time mod_name [DotO obj_fn, DotO stub_fn]))
790              else return (Just (LM obj_time mod_name [DotO obj_fn]))
791
792
793 -----------------------------------------------------------------------------
794 -- Do a pre-upsweep without use of "compile", to establish a 
795 -- (downward-closed) set of stable modules for which we won't call compile.
796
797 -- a stable module:
798 --      * has a valid linkable (see getValidLinkables above)
799 --      * depends only on stable modules
800 --      * has an interface in the HIT (interactive mode only)
801
802 preUpsweep :: [Linkable]        -- new valid linkables
803            -> HomeIfaceTable
804            -> [ModuleName]      -- names of all mods encountered in downsweep
805            -> [ModuleName]      -- accumulating stable modules
806            -> [SCC ModSummary]  -- scc-ified mod graph, including src imps
807            -> IO [ModuleName]   -- stable modules
808
809 preUpsweep valid_lis hit all_home_mods stable []  = return stable
810 preUpsweep valid_lis hit all_home_mods stable (scc0:sccs)
811    = do let scc = flattenSCC scc0
812             scc_allhomeimps :: [ModuleName]
813             scc_allhomeimps 
814                = nub (filter (`elem` all_home_mods) (concatMap ms_allimps scc))
815             all_imports_in_scc_or_stable
816                = all in_stable_or_scc scc_allhomeimps
817             scc_names
818                = map name_of_summary scc
819             in_stable_or_scc m
820                = m `elem` scc_names || m `elem` stable
821
822             -- now we check for valid linkables: each module in the SCC must 
823             -- have a valid linkable (see getValidLinkables above).
824             has_valid_linkable new_summary
825               = isJust (findModuleLinkable_maybe valid_lis modname)
826                where modname = name_of_summary new_summary
827
828             has_interface summary = ms_mod summary `elemUFM` hit
829
830             scc_is_stable = all_imports_in_scc_or_stable
831                           && all has_valid_linkable scc
832                           && all has_interface scc
833
834         if scc_is_stable
835          then preUpsweep valid_lis hit all_home_mods (scc_names++stable) sccs
836          else preUpsweep valid_lis hit all_home_mods stable sccs
837
838
839 -- Helper for preUpsweep.  Assuming that new_summary's imports are all
840 -- stable (in the sense of preUpsweep), determine if new_summary is itself
841 -- stable, and, if so, in batch mode, return its linkable.
842 findInSummaries :: [ModSummary] -> ModuleName -> [ModSummary]
843 findInSummaries old_summaries mod_name
844    = [s | s <- old_summaries, name_of_summary s == mod_name]
845
846 findModInSummaries :: [ModSummary] -> Module -> Maybe ModSummary
847 findModInSummaries old_summaries mod
848    = case [s | s <- old_summaries, ms_mod s == mod] of
849          [] -> Nothing
850          (s:_) -> Just s
851
852 -- Return (names of) all those in modsDone who are part of a cycle
853 -- as defined by theGraph.
854 findPartiallyCompletedCycles :: [ModuleName] -> [SCC ModSummary] -> [ModuleName]
855 findPartiallyCompletedCycles modsDone theGraph
856    = chew theGraph
857      where
858         chew [] = []
859         chew ((AcyclicSCC v):rest) = chew rest    -- acyclic?  not interesting.
860         chew ((CyclicSCC vs):rest)
861            = let names_in_this_cycle = nub (map name_of_summary vs)
862                  mods_in_this_cycle  
863                     = nub ([done | done <- modsDone, 
864                                    done `elem` names_in_this_cycle])
865                  chewed_rest = chew rest
866              in 
867              if   not (null mods_in_this_cycle) 
868                   && length mods_in_this_cycle < length names_in_this_cycle
869              then mods_in_this_cycle ++ chewed_rest
870              else chewed_rest
871
872
873 -- Add the given (LM-form) Linkables to the UI, overwriting previous
874 -- versions if they exist.
875 add_to_ui :: UnlinkedImage -> [Linkable] -> UnlinkedImage
876 add_to_ui ui lis
877    = filter (not_in lis) ui ++ lis
878      where
879         not_in :: [Linkable] -> Linkable -> Bool
880         not_in lis li
881            = all (\l -> linkableModName l /= mod) lis
882            where mod = linkableModName li
883                                   
884
885 data CmThreaded  -- stuff threaded through individual module compilations
886    = CmThreaded PersistentCompilerState HomeSymbolTable HomeIfaceTable
887
888
889 -- Compile multiple modules, stopping as soon as an error appears.
890 -- There better had not be any cyclic groups here -- we check for them.
891 upsweep_mods :: GhciMode
892              -> DynFlags
893              -> UnlinkedImage         -- valid linkables
894              -> (ModuleName -> [ModuleName])  -- to construct downward closures
895              -> CmThreaded            -- PCS & HST & HIT
896              -> IO ()                 -- how to clean up unwanted tmp files
897              -> [SCC ModSummary]      -- mods to do (the worklist)
898                                       -- ...... RETURNING ......
899              -> IO (Bool{-complete success?-},
900                     CmThreaded,
901                     [ModSummary],     -- mods which succeeded
902                     [Linkable])       -- new linkables
903
904 upsweep_mods ghci_mode dflags oldUI reachable_from threaded cleanup
905      []
906    = return (True, threaded, [], [])
907
908 upsweep_mods ghci_mode dflags oldUI reachable_from threaded cleanup
909      ((CyclicSCC ms):_)
910    = do hPutStrLn stderr ("Module imports form a cycle for modules:\n\t" ++
911                           unwords (map (moduleNameUserString.name_of_summary) ms))
912         return (False, threaded, [], [])
913
914 upsweep_mods ghci_mode dflags oldUI reachable_from threaded cleanup
915      ((AcyclicSCC mod):mods)
916    = do --case threaded of
917         --   CmThreaded pcsz hstz hitz
918         --      -> putStrLn ("UPSWEEP_MOD: hit = " ++ show (map (moduleNameUserString.moduleName.mi_module) (eltsUFM hitz)))
919
920         (threaded1, maybe_linkable) 
921            <- upsweep_mod ghci_mode dflags oldUI threaded mod 
922                           (reachable_from (name_of_summary mod))
923
924         -- remove unwanted tmp files between compilations
925         cleanup
926
927         case maybe_linkable of
928            Just linkable 
929               -> -- No errors; do the rest
930                  do (restOK, threaded2, modOKs, linkables) 
931                        <- upsweep_mods ghci_mode dflags oldUI reachable_from 
932                                        threaded1 cleanup mods
933                     return (restOK, threaded2, mod:modOKs, linkable:linkables)
934            Nothing -- we got a compilation error; give up now
935               -> return (False, threaded1, [], [])
936
937
938 -- Compile a single module.  Always produce a Linkable for it if 
939 -- successful.  If no compilation happened, return the old Linkable.
940 upsweep_mod :: GhciMode 
941             -> DynFlags
942             -> UnlinkedImage
943             -> CmThreaded
944             -> ModSummary
945             -> [ModuleName]
946             -> IO (CmThreaded, Maybe Linkable)
947
948 upsweep_mod ghci_mode dflags oldUI threaded1 summary1 reachable_inc_me
949    = do 
950         let mod_name = name_of_summary summary1
951
952         let (CmThreaded pcs1 hst1 hit1) = threaded1
953         let old_iface = lookupUFM hit1 mod_name
954
955         let maybe_old_linkable = findModuleLinkable_maybe oldUI mod_name
956
957             source_unchanged = isJust maybe_old_linkable
958
959             reachable_only = filter (/= (name_of_summary summary1)) 
960                                 reachable_inc_me
961
962            -- in interactive mode, all home modules below us *must* have an
963            -- interface in the HIT.  We never demand-load home interfaces in
964            -- interactive mode.
965             (hst1_strictDC, hit1_strictDC, [])
966                = ASSERT(ghci_mode == Batch || 
967                         all (`elemUFM` hit1) reachable_only)
968                  retainInTopLevelEnvs reachable_only (hst1,hit1,[])
969
970             old_linkable 
971                = unJust "upsweep_mod:old_linkable" maybe_old_linkable
972
973             have_object 
974                | Just l <- maybe_old_linkable, isObjectLinkable l = True
975                | otherwise = False
976
977         compresult <- compile ghci_mode summary1 source_unchanged
978                          have_object old_iface hst1_strictDC hit1_strictDC pcs1
979
980         case compresult of
981
982            -- Compilation "succeeded", and may or may not have returned a new
983            -- linkable (depending on whether compilation was actually performed
984            -- or not).
985            CompOK pcs2 new_details new_iface maybe_new_linkable
986               -> do let hst2      = addToUFM hst1 mod_name new_details
987                         hit2      = addToUFM hit1 mod_name new_iface
988                         threaded2 = CmThreaded pcs2 hst2 hit2
989
990                     return (threaded2, if isJust maybe_new_linkable
991                                           then maybe_new_linkable
992                                           else Just old_linkable)
993
994            -- Compilation failed.  compile may still have updated
995            -- the PCS, tho.
996            CompErrs pcs2
997               -> do let threaded2 = CmThreaded pcs2 hst1 hit1
998                     return (threaded2, Nothing)
999
1000 -- Filter modules in the top level envs (HST, HIT, UI).
1001 retainInTopLevelEnvs :: [ModuleName]
1002                         -> (HomeSymbolTable, HomeIfaceTable, UnlinkedImage)
1003                         -> (HomeSymbolTable, HomeIfaceTable, UnlinkedImage)
1004 retainInTopLevelEnvs keep_these (hst, hit, ui)
1005    = (retainInUFM hst keep_these,
1006       retainInUFM hit keep_these,
1007       filterModuleLinkables (`elem` keep_these) ui
1008      )
1009      where
1010         retainInUFM :: Uniquable key => UniqFM elt -> [key] -> UniqFM elt
1011         retainInUFM ufm keys_to_keep
1012            = listToUFM (concatMap (maybeLookupUFM ufm) keys_to_keep)
1013         maybeLookupUFM ufm u 
1014            = case lookupUFM ufm u of Nothing -> []; Just val -> [(u, val)] 
1015
1016 -- Needed to clean up HIT and HST so that we don't get duplicates in inst env
1017 downwards_closure_of_module :: [ModSummary] -> ModuleName -> [ModuleName]
1018 downwards_closure_of_module summaries root
1019    = let toEdge :: ModSummary -> (ModuleName,[ModuleName])
1020          toEdge summ = (name_of_summary summ, 
1021                         filter (`elem` all_mods) (ms_allimps summ))
1022
1023          all_mods = map name_of_summary summaries
1024
1025          res = simple_transitive_closure (map toEdge summaries) [root]
1026      in
1027 --         trace (showSDoc (text "DC of mod" <+> ppr root
1028 --                          <+> text "=" <+> ppr res)) $
1029          res
1030
1031 -- Calculate transitive closures from a set of roots given an adjacency list
1032 simple_transitive_closure :: Eq a => [(a,[a])] -> [a] -> [a]
1033 simple_transitive_closure graph set 
1034    = let set2      = nub (concatMap dsts set ++ set)
1035          dsts node = fromMaybe [] (lookup node graph)
1036      in
1037          if   length set == length set2
1038          then set
1039          else simple_transitive_closure graph set2
1040
1041
1042 -- Calculate SCCs of the module graph, with or without taking into
1043 -- account source imports.
1044 topological_sort :: Bool -> [ModSummary] -> [SCC ModSummary]
1045 topological_sort include_source_imports summaries
1046    = let 
1047          toEdge :: ModSummary -> (ModSummary,ModuleName,[ModuleName])
1048          toEdge summ
1049              = (summ, name_of_summary summ, 
1050                       (if include_source_imports 
1051                        then ms_srcimps summ else []) ++ ms_imps summ)
1052         
1053          mash_edge :: (ModSummary,ModuleName,[ModuleName]) -> (ModSummary,Int,[Int])
1054          mash_edge (summ, m, m_imports)
1055             = case lookup m key_map of
1056                  Nothing -> panic "reverse_topological_sort"
1057                  Just mk -> (summ, mk, 
1058                                 -- ignore imports not from the home package
1059                                 catMaybes (map (flip lookup key_map) m_imports))
1060
1061          edges     = map toEdge summaries
1062          key_map   = zip [nm | (s,nm,imps) <- edges] [1 ..] :: [(ModuleName,Int)]
1063          scc_input = map mash_edge edges
1064          sccs      = stronglyConnComp scc_input
1065      in
1066          sccs
1067
1068
1069 -----------------------------------------------------------------------------
1070 -- Downsweep (dependency analysis)
1071
1072 -- Chase downwards from the specified root set, returning summaries
1073 -- for all home modules encountered.  Only follow source-import
1074 -- links.
1075
1076 -- We pass in the previous collection of summaries, which is used as a
1077 -- cache to avoid recalculating a module summary if the source is
1078 -- unchanged.
1079
1080 downsweep :: [FilePath] -> [ModSummary] -> IO [ModSummary]
1081 downsweep roots old_summaries
1082    = do rootSummaries <- mapM getRootSummary roots
1083         all_summaries
1084            <- loop (concat (map ms_imps rootSummaries))
1085                 (mkModuleEnv [ (mod, s) | s <- rootSummaries, 
1086                                           let mod = ms_mod s, isHomeModule mod 
1087                              ])
1088         return all_summaries
1089      where
1090         getRootSummary :: FilePath -> IO ModSummary
1091         getRootSummary file
1092            | haskellish_src_file file
1093            = do exists <- doesFileExist file
1094                 if exists then summariseFile file else do
1095                 throwDyn (CmdLineError ("can't find file `" ++ file ++ "'"))    
1096            | otherwise
1097            = do exists <- doesFileExist hs_file
1098                 if exists then summariseFile hs_file else do
1099                 exists <- doesFileExist lhs_file
1100                 if exists then summariseFile lhs_file else do
1101                 let mod_name = mkModuleName file
1102                 maybe_summary <- getSummary mod_name
1103                 case maybe_summary of
1104                    Nothing -> packageModErr mod_name
1105                    Just s  -> return s
1106            where 
1107                  hs_file = file ++ ".hs"
1108                  lhs_file = file ++ ".lhs"
1109
1110         getSummary :: ModuleName -> IO (Maybe ModSummary)
1111         getSummary nm
1112            = do found <- findModule nm
1113                 case found of
1114                    Just (mod, location) -> do
1115                         let old_summary = findModInSummaries old_summaries mod
1116                         summarise mod location old_summary
1117
1118                    Nothing -> throwDyn (CmdLineError 
1119                                    ("can't find module `" 
1120                                      ++ showSDoc (ppr nm) ++ "'"))
1121
1122         -- loop invariant: env doesn't contain package modules
1123         loop :: [ModuleName] -> ModuleEnv ModSummary -> IO [ModSummary]
1124         loop [] env = return (moduleEnvElts env)
1125         loop imps env
1126            = do -- imports for modules we don't already have
1127                 let needed_imps = nub (filter (not . (`elemUFM` env)) imps)
1128
1129                 -- summarise them
1130                 needed_summaries <- mapM getSummary needed_imps
1131
1132                 -- get just the "home" modules
1133                 let new_home_summaries = [ s | Just s <- needed_summaries ]
1134
1135                 -- loop, checking the new imports
1136                 let new_imps = concat (map ms_imps new_home_summaries)
1137                 loop new_imps (extendModuleEnvList env 
1138                                 [ (ms_mod s, s) | s <- new_home_summaries ])
1139
1140 -----------------------------------------------------------------------------
1141 -- Summarising modules
1142
1143 -- We have two types of summarisation:
1144 --
1145 --    * Summarise a file.  This is used for the root module(s) passed to
1146 --      cmLoadModules.  The file is read, and used to determine the root
1147 --      module name.  The module name may differ from the filename.
1148 --
1149 --    * Summarise a module.  We are given a module name, and must provide
1150 --      a summary.  The finder is used to locate the file in which the module
1151 --      resides.
1152
1153 summariseFile :: FilePath -> IO ModSummary
1154 summariseFile file
1155    = do hspp_fn <- preprocess file
1156         (srcimps,imps,mod_name) <- getImportsFromFile hspp_fn
1157
1158         let (path, basename, _ext) = splitFilename3 file
1159
1160         (mod, location)
1161            <- mkHomeModuleLocn mod_name (path ++ '/':basename) file
1162
1163         src_timestamp
1164            <- case ml_hs_file location of 
1165                  Nothing     -> noHsFileErr mod_name
1166                  Just src_fn -> getModificationTime src_fn
1167
1168         return (ModSummary mod
1169                            location{ml_hspp_file=Just hspp_fn}
1170                            srcimps imps src_timestamp)
1171
1172 -- Summarise a module, and pick up source and timestamp.
1173 summarise :: Module -> ModuleLocation -> Maybe ModSummary
1174          -> IO (Maybe ModSummary)
1175 summarise mod location old_summary
1176    | not (isHomeModule mod) = return Nothing
1177    | otherwise
1178    = do let hs_fn = unJust "summarise" (ml_hs_file location)
1179
1180         case ml_hs_file location of {
1181            Nothing -> noHsFileErr mod;
1182            Just src_fn -> do
1183
1184         src_timestamp <- getModificationTime src_fn
1185
1186         -- return the cached summary if the source didn't change
1187         case old_summary of {
1188            Just s | ms_hs_date s == src_timestamp -> return (Just s);
1189            _ -> do
1190
1191         hspp_fn <- preprocess hs_fn
1192         (srcimps,imps,mod_name) <- getImportsFromFile hspp_fn
1193
1194         when (mod_name /= moduleName mod) $
1195                 throwDyn (ProgramError 
1196                    (showSDoc (text hs_fn
1197                               <>  text ": file name does not match module name"
1198                               <+> quotes (ppr (moduleName mod)))))
1199
1200         return (Just (ModSummary mod location{ml_hspp_file=Just hspp_fn} 
1201                                  srcimps imps src_timestamp))
1202         }
1203       }
1204
1205
1206 noHsFileErr mod
1207   = throwDyn (CmdLineError (showSDoc (text "no source file for module" <+> quotes (ppr mod))))
1208
1209 packageModErr mod
1210   = throwDyn (CmdLineError (showSDoc (text "module" <+>
1211                                    quotes (ppr mod) <+>
1212                                    text "is a package module")))
1213 \end{code}