2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-2000
5 \section[GHC_Main]{Main driver for Glasgow Haskell compiler}
10 hscMain, newHscEnv, hscCmmFile,
14 hscStmt, hscTcExpr, hscKcType,
15 hscGetInfo, GetInfoResult,
20 #include "HsVersions.h"
23 import HsSyn ( Stmt(..), LHsExpr, LStmt, LHsType )
24 import IfaceSyn ( IfaceDecl, IfaceInst )
25 import Module ( Module )
26 import CodeOutput ( outputForeignStubs )
27 import ByteCodeGen ( byteCodeGen, coreExprToBCOs )
28 import Linker ( HValue, linkExpr )
29 import CoreTidy ( tidyExpr )
30 import CorePrep ( corePrepExpr )
31 import Flattening ( flattenExpr )
32 import TcRnDriver ( tcRnStmt, tcRnExpr, tcRnGetInfo, GetInfoResult, tcRnType )
33 import RdrName ( rdrNameOcc )
34 import OccName ( occNameUserString )
36 import PrelNames ( iNTERACTIVE )
38 import CoreLint ( lintUnfolding )
39 import DsMeta ( templateHaskellNames )
40 import BasicTypes ( Fixity )
41 import SrcLoc ( SrcLoc, noSrcLoc )
42 import VarEnv ( emptyTidyEnv )
46 import Module ( emptyModuleEnv )
47 import RdrName ( GlobalRdrEnv, RdrName )
48 import HsSyn ( HsModule, LHsBinds, HsGroup )
49 import SrcLoc ( Located(..) )
50 import StringBuffer ( hGetStringBuffer, stringToStringBuffer )
52 import Lexer ( P(..), ParseResult(..), mkPState )
53 import SrcLoc ( mkSrcLoc )
54 import TcRnDriver ( tcRnModule, tcRnExtCore )
55 import TcIface ( typecheckIface )
56 import TcRnMonad ( initIfaceCheck, TcGblEnv(..) )
57 import IfaceEnv ( initNameCache )
58 import LoadIface ( ifaceStats, initExternalPackageState )
59 import PrelInfo ( wiredInThings, basicKnownKeyNames )
60 import MkIface ( checkOldIface, mkIface, writeIfaceFile )
62 import Flattening ( flatten )
64 import TidyPgm ( optTidyPgm, simpleTidyPgm )
65 import CorePrep ( corePrepPgm )
66 import CoreToStg ( coreToStg )
67 import Name ( Name, NamedThing(..) )
68 import SimplStg ( stg2stg )
69 import CodeGen ( codeGen )
70 import CmmParse ( parseCmmFile )
71 import CodeOutput ( codeOutput )
74 import DriverPhases ( HscSource(..) )
76 import UniqSupply ( mkSplitUniqSupply )
79 import HscStats ( ppSourceStats )
81 import MkExternalCore ( emitExternalCore )
83 import ParserCoreUtils
85 import Maybes ( expectJust )
86 import Bag ( unitBag, emptyBag )
88 import Maybe ( isJust )
90 import DATA_IOREF ( newIORef, readIORef )
94 %************************************************************************
98 %************************************************************************
101 newHscEnv :: DynFlags -> IO HscEnv
103 = do { eps_var <- newIORef initExternalPackageState
104 ; us <- mkSplitUniqSupply 'r'
105 ; nc_var <- newIORef (initNameCache us knownKeyNames)
106 ; fc_var <- newIORef emptyModuleEnv
107 ; return (HscEnv { hsc_dflags = dflags,
110 hsc_IC = emptyInteractiveContext,
111 hsc_HPT = emptyHomePackageTable,
114 hsc_FC = fc_var } ) }
117 knownKeyNames :: [Name] -- Put here to avoid loops involving DsMeta,
118 -- where templateHaskellNames are defined
119 knownKeyNames = map getName wiredInThings
120 ++ basicKnownKeyNames
122 ++ templateHaskellNames
127 %************************************************************************
129 The main compiler pipeline
131 %************************************************************************
135 -- Compilation failed
138 -- In IDE mode: we just do the static/dynamic checks
140 (Located (HsModule RdrName)) -- parsed
141 (Maybe (HsGroup Name)) -- renamed
142 (Maybe (LHsBinds Id, GlobalRdrEnv, ModDetails)) -- typechecked
144 -- Concluded that it wasn't necessary
145 | HscNoRecomp ModDetails -- new details (HomeSymbolTable additions)
146 ModIface -- new iface (if any compilation was done)
149 | HscRecomp ModDetails -- new details (HomeSymbolTable additions)
150 ModIface -- new iface (if any compilation was done)
151 Bool -- stub_h exists
152 Bool -- stub_c exists
153 (Maybe CompiledByteCode)
156 -- What to do when we have compiler error or warning messages
157 type MessageAction = Messages -> IO ()
159 -- no errors or warnings; the individual passes
160 -- (parse/rename/typecheck) print messages themselves
164 -> MessageAction -- What to do with errors/warnings
166 -> Bool -- True <=> source unchanged
167 -> Bool -- True <=> have an object file (for msgs only)
168 -> Maybe ModIface -- Old interface, if available
169 -> Maybe (Int, Int) -- Just (i,n) <=> module i of n (for msgs)
172 hscMain hsc_env msg_act mod_summary
173 source_unchanged have_object maybe_old_iface
176 (recomp_reqd, maybe_checked_iface) <-
177 {-# SCC "checkOldIface" #-}
178 checkOldIface hsc_env mod_summary
179 source_unchanged maybe_old_iface;
181 let no_old_iface = not (isJust maybe_checked_iface)
182 what_next | recomp_reqd || no_old_iface = hscRecomp
183 | otherwise = hscNoRecomp
185 ; what_next hsc_env msg_act mod_summary have_object
191 ------------------------------
192 hscNoRecomp hsc_env msg_act mod_summary
193 have_object (Just old_iface)
195 | isOneShot (ghcMode (hsc_dflags hsc_env))
197 compilationProgressMsg (hsc_dflags hsc_env) $
198 "compilation IS NOT required";
199 dumpIfaceStats hsc_env ;
201 let { bomb = panic "hscNoRecomp:OneShot" };
202 return (HscNoRecomp bomb bomb)
205 = do { compilationProgressMsg (hsc_dflags hsc_env) $
206 (showModuleIndex mb_mod_index ++
207 "Skipping " ++ showModMsg have_object mod_summary)
209 ; new_details <- {-# SCC "tcRnIface" #-}
210 initIfaceCheck hsc_env $
211 typecheckIface old_iface ;
212 ; dumpIfaceStats hsc_env
214 ; return (HscNoRecomp new_details old_iface)
217 hscNoRecomp hsc_env msg_act mod_summary
220 = panic "hscNoRecomp" -- hscNoRecomp definitely expects to
221 -- have the old interface available
223 ------------------------------
224 hscRecomp hsc_env msg_act mod_summary
225 have_object maybe_old_iface
227 = case ms_hsc_src mod_summary of
229 front_res <- hscFileFrontEnd hsc_env msg_act mod_summary mb_mod_index
230 hscBackEnd hsc_env mod_summary maybe_old_iface front_res
233 front_res <- hscFileFrontEnd hsc_env msg_act mod_summary mb_mod_index
234 hscBootBackEnd hsc_env mod_summary maybe_old_iface front_res
237 front_res <- hscCoreFrontEnd hsc_env msg_act mod_summary
238 hscBackEnd hsc_env mod_summary maybe_old_iface front_res
240 hscCoreFrontEnd hsc_env msg_act mod_summary = do {
244 ; inp <- readFile (expectJust "hscCoreFrontEnd" (ms_hspp_file mod_summary))
245 ; case parseCore inp 1 of
246 FailP s -> putMsg s{-ToDo: wrong-} >> return Nothing
247 OkP rdr_module -> do {
250 -- RENAME and TYPECHECK
252 ; (tc_msgs, maybe_tc_result) <- {-# SCC "TypeCheck" #-}
253 tcRnExtCore hsc_env rdr_module
255 ; case maybe_tc_result of
256 Nothing -> return Nothing
257 Just mod_guts -> return (Just mod_guts) -- No desugaring to do!
261 hscFileFrontEnd hsc_env msg_act mod_summary mb_mod_index = do {
263 -- DISPLAY PROGRESS MESSAGE
265 let one_shot = isOneShot (ghcMode (hsc_dflags hsc_env))
266 ; let dflags = hsc_dflags hsc_env
267 ; let toInterp = hscTarget dflags == HscInterpreted
268 ; when (not one_shot) $
269 compilationProgressMsg dflags $
270 (showModuleIndex mb_mod_index ++
271 "Compiling " ++ showModMsg (not toInterp) mod_summary)
276 ; let hspp_file = expectJust "hscFileFrontEnd" (ms_hspp_file mod_summary)
277 hspp_buf = ms_hspp_buf mod_summary
279 ; maybe_parsed <- myParseModule (hsc_dflags hsc_env) hspp_file hspp_buf
281 ; case maybe_parsed of {
282 Left err -> do { msg_act (unitBag err, emptyBag)
284 Right rdr_module -> do {
287 -- RENAME and TYPECHECK
289 (tc_msgs, maybe_tc_result)
290 <- {-# SCC "Typecheck-Rename" #-}
291 tcRnModule hsc_env (ms_hsc_src mod_summary) False rdr_module
294 ; case maybe_tc_result of {
295 Nothing -> return Nothing ;
296 Just tc_result -> do {
301 ; (warns, maybe_ds_result) <- {-# SCC "DeSugar" #-}
302 deSugar hsc_env tc_result
303 ; msg_act (warns, emptyBag)
304 ; return maybe_ds_result
307 ------------------------------
309 hscFileCheck :: HscEnv -> MessageAction -> ModSummary -> IO HscResult
310 hscFileCheck hsc_env msg_act mod_summary = do {
314 ; let hspp_file = expectJust "hscFileFrontEnd" (ms_hspp_file mod_summary)
315 hspp_buf = ms_hspp_buf mod_summary
317 ; maybe_parsed <- myParseModule (hsc_dflags hsc_env) hspp_file hspp_buf
319 ; case maybe_parsed of {
320 Left err -> do { msg_act (unitBag err, emptyBag)
322 Right rdr_module -> do {
325 -- RENAME and TYPECHECK
327 (tc_msgs, maybe_tc_result)
328 <- _scc_ "Typecheck-Rename"
329 tcRnModule hsc_env (ms_hsc_src mod_summary)
330 True{-save renamed syntax-}
334 ; case maybe_tc_result of {
335 Nothing -> return (HscChecked rdr_module Nothing Nothing);
337 let md = ModDetails {
338 md_types = tcg_type_env tc_result,
339 md_exports = tcg_exports tc_result,
340 md_insts = tcg_insts tc_result,
341 md_rules = [panic "no rules"] }
342 -- Rules are CoreRules, not the
343 -- RuleDecls we get out of the typechecker
344 return (HscChecked rdr_module
345 (tcg_rn_decls tc_result)
346 (Just (tcg_binds tc_result,
347 tcg_rdr_env tc_result,
351 ------------------------------
352 hscBootBackEnd :: HscEnv -> ModSummary -> Maybe ModIface -> Maybe ModGuts -> IO HscResult
353 -- For hs-boot files, there's no code generation to do
355 hscBootBackEnd hsc_env mod_summary maybe_old_iface Nothing
357 hscBootBackEnd hsc_env mod_summary maybe_old_iface (Just ds_result)
358 = do { tidy_pgm <- simpleTidyPgm hsc_env ds_result
360 ; (new_iface, no_change)
361 <- {-# SCC "MkFinalIface" #-}
362 mkIface hsc_env maybe_old_iface tidy_pgm
364 ; writeIfaceFile hsc_env (ms_location mod_summary) new_iface no_change
366 ; let { final_details = ModDetails { md_types = mg_types ds_result,
367 md_exports = mg_exports ds_result,
368 md_insts = mg_insts ds_result,
369 md_rules = mg_rules ds_result } }
370 -- And the answer is ...
371 ; dumpIfaceStats hsc_env
373 ; return (HscRecomp final_details
378 ------------------------------
379 hscBackEnd :: HscEnv -> ModSummary -> Maybe ModIface -> Maybe ModGuts -> IO HscResult
381 hscBackEnd hsc_env mod_summary maybe_old_iface Nothing
384 hscBackEnd hsc_env mod_summary maybe_old_iface (Just ds_result)
386 -- ; seqList imported_modules (return ())
388 let one_shot = isOneShot (ghcMode dflags)
389 dflags = hsc_dflags hsc_env
394 ; flat_result <- {-# SCC "Flattening" #-}
395 flatten hsc_env ds_result
398 {- TEMP: need to review space-leak fixing here
399 NB: even the code generator can force one of the
400 thunks for constructor arguments, for newtypes in particular
402 ; let -- Rule-base accumulated from imported packages
403 pkg_rule_base = eps_rule_base (hsc_EPS hsc_env)
405 -- In one-shot mode, ZAP the external package state at
406 -- this point, because we aren't going to need it from
407 -- now on. We keep the name cache, however, because
408 -- tidyCore needs it.
410 | one_shot = pcs_tc{ pcs_EPS = error "pcs_EPS missing" }
413 ; pkg_rule_base `seq` pcs_middle `seq` return ()
416 -- alive at this point:
424 ; simpl_result <- {-# SCC "Core2Core" #-}
425 core2core hsc_env flat_result
430 ; let omit_prags = dopt Opt_OmitInterfacePragmas dflags
431 ; tidy_result <- {-# SCC "CoreTidy" #-}
433 then simpleTidyPgm hsc_env simpl_result
434 else optTidyPgm hsc_env simpl_result
436 -- Emit external core
437 ; emitExternalCore dflags tidy_result
439 -- Alive at this point:
440 -- tidy_result, pcs_final
444 -- BUILD THE NEW ModIface and ModDetails
445 -- and emit external core if necessary
446 -- This has to happen *after* code gen so that the back-end
447 -- info has been set. Not yet clear if it matters waiting
448 -- until after code output
449 ; (new_iface, no_change) <- {-# SCC "MkFinalIface" #-}
450 mkIface hsc_env maybe_old_iface tidy_result
452 ; writeIfaceFile hsc_env (ms_location mod_summary) new_iface no_change
454 -- Space leak reduction: throw away the new interface if
455 -- we're in one-shot mode; we won't be needing it any
457 ; final_iface <- if one_shot then return (error "no final iface")
458 else return new_iface
460 -- Build the final ModDetails (except in one-shot mode, where
461 -- we won't need this information after compilation).
463 if one_shot then return (error "no final details")
464 else return $! ModDetails {
465 md_types = mg_types tidy_result,
466 md_exports = mg_exports tidy_result,
467 md_insts = mg_insts tidy_result,
468 md_rules = mg_rules tidy_result }
471 -- CONVERT TO STG and COMPLETE CODE GENERATION
472 ; (stub_h_exists, stub_c_exists, maybe_bcos)
473 <- hscCodeGen dflags tidy_result
475 -- And the answer is ...
476 ; dumpIfaceStats hsc_env
478 ; return (HscRecomp final_details
480 stub_h_exists stub_c_exists
487 ModGuts{ -- This is the last use of the ModGuts in a compilation.
488 -- From now on, we just use the bits we need.
489 mg_module = this_mod,
490 mg_binds = core_binds,
492 mg_dir_imps = dir_imps,
493 mg_foreign = foreign_stubs,
494 mg_deps = dependencies } = do {
497 -- PREPARE FOR CODE GENERATION
498 -- Do saturation and convert to A-normal form
499 prepd_binds <- {-# SCC "CorePrep" #-}
500 corePrepPgm dflags core_binds type_env;
502 case hscTarget dflags of
503 HscNothing -> return (False, False, Nothing)
507 do ----------------- Generate byte code ------------------
508 comp_bc <- byteCodeGen dflags prepd_binds type_env
510 ------------------ Create f-x-dynamic C-side stuff ---
511 (istub_h_exists, istub_c_exists)
512 <- outputForeignStubs dflags foreign_stubs
514 return ( istub_h_exists, istub_c_exists, Just comp_bc )
516 panic "GHC not compiled with interpreter"
521 ----------------- Convert to STG ------------------
522 (stg_binds, cost_centre_info) <- {-# SCC "CoreToStg" #-}
523 myCoreToStg dflags this_mod prepd_binds
525 ------------------ Code generation ------------------
526 abstractC <- {-# SCC "CodeGen" #-}
527 codeGen dflags this_mod type_env foreign_stubs
528 dir_imps cost_centre_info stg_binds
530 ------------------ Code output -----------------------
531 (stub_h_exists, stub_c_exists)
532 <- codeOutput dflags this_mod foreign_stubs
533 dependencies abstractC
535 return (stub_h_exists, stub_c_exists, Nothing)
539 hscCmmFile :: DynFlags -> FilePath -> IO Bool
540 hscCmmFile dflags filename = do
541 maybe_cmm <- parseCmmFile dflags filename
543 Nothing -> return False
545 codeOutput dflags no_mod NoStubs noDependencies [cmm]
548 no_mod = panic "hscCmmFile: no_mod"
551 myParseModule dflags src_filename maybe_src_buf
552 = -------------------------- Parser ----------------
553 showPass dflags "Parser" >>
554 {-# SCC "Parser" #-} do
556 -- sometimes we already have the buffer in memory, perhaps
557 -- because we needed to parse the imports out of it, or get the
559 buf <- case maybe_src_buf of
561 Nothing -> hGetStringBuffer src_filename
563 let loc = mkSrcLoc (mkFastString src_filename) 1 0
565 case unP parseModule (mkPState buf loc dflags) of {
567 PFailed span err -> return (Left (mkPlainErrMsg span err));
569 POk _ rdr_module -> do {
571 dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_module) ;
573 dumpIfSet_dyn dflags Opt_D_source_stats "Source Statistics"
574 (ppSourceStats False rdr_module) ;
576 return (Right rdr_module)
577 -- ToDo: free the string buffer later.
581 myCoreToStg dflags this_mod prepd_binds
583 stg_binds <- {-# SCC "Core2Stg" #-}
584 coreToStg dflags prepd_binds
586 (stg_binds2, cost_centre_info) <- {-# SCC "Core2Stg" #-}
587 stg2stg dflags this_mod stg_binds
589 return (stg_binds2, cost_centre_info)
593 %************************************************************************
595 \subsection{Compiling a do-statement}
597 %************************************************************************
599 When the UnlinkedBCOExpr is linked you get an HValue of type
601 When you run it you get a list of HValues that should be
602 the same length as the list of names; add them to the ClosureEnv.
604 A naked expression returns a singleton Name [it].
606 What you type The IO [HValue] that hscStmt returns
607 ------------- ------------------------------------
608 let pat = expr ==> let pat = expr in return [coerce HVal x, coerce HVal y, ...]
611 pat <- expr ==> expr >>= \ pat -> return [coerce HVal x, coerce HVal y, ...]
614 expr (of IO type) ==> expr >>= \ v -> return [v]
615 [NB: result not printed] bindings: [it]
618 expr (of non-IO type,
619 result showable) ==> let v = expr in print v >> return [v]
622 expr (of non-IO type,
623 result not showable) ==> error
627 hscStmt -- Compile a stmt all the way to an HValue, but don't run it
629 -> String -- The statement
630 -> IO (Maybe (HscEnv, [Name], HValue))
633 = do { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) stmt
634 ; case maybe_stmt of {
635 Nothing -> return Nothing ; -- Parse error
636 Just Nothing -> return Nothing ; -- Empty line
637 Just (Just parsed_stmt) -> do { -- The real stuff
639 -- Rename and typecheck it
640 let icontext = hsc_IC hsc_env
641 ; maybe_tc_result <- tcRnStmt hsc_env icontext parsed_stmt
643 ; case maybe_tc_result of {
644 Nothing -> return Nothing ;
645 Just (new_ic, bound_names, tc_expr) -> do {
647 -- Then desugar, code gen, and link it
648 ; hval <- compileExpr hsc_env iNTERACTIVE
649 (ic_rn_gbl_env new_ic)
653 ; return (Just (hsc_env{ hsc_IC=new_ic }, bound_names, hval))
656 hscTcExpr -- Typecheck an expression (but don't run it)
658 -> String -- The expression
661 hscTcExpr hsc_env expr
662 = do { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) expr
663 ; let icontext = hsc_IC hsc_env
664 ; case maybe_stmt of {
665 Nothing -> return Nothing ; -- Parse error
666 Just (Just (L _ (ExprStmt expr _ _)))
667 -> tcRnExpr hsc_env icontext expr ;
668 Just other -> do { errorMsg ("not an expression: `" ++ expr ++ "'") ;
672 hscKcType -- Find the kind of a type
674 -> String -- The type
677 hscKcType hsc_env str
678 = do { maybe_type <- hscParseType (hsc_dflags hsc_env) str
679 ; let icontext = hsc_IC hsc_env
680 ; case maybe_type of {
681 Just ty -> tcRnType hsc_env icontext ty ;
682 Just other -> do { errorMsg ("not an type: `" ++ str ++ "'") ;
684 Nothing -> return Nothing } }
690 hscParseStmt :: DynFlags -> String -> IO (Maybe (Maybe (LStmt RdrName)))
691 hscParseStmt = hscParseThing parseStmt
693 hscParseType :: DynFlags -> String -> IO (Maybe (LHsType RdrName))
694 hscParseType = hscParseThing parseType
697 hscParseIdentifier :: DynFlags -> String -> IO (Maybe (Located RdrName))
698 hscParseIdentifier = hscParseThing parseIdentifier
700 hscParseThing :: Outputable thing
702 -> DynFlags -> String
704 -- Nothing => Parse error (message already printed)
706 hscParseThing parser dflags str
707 = showPass dflags "Parser" >>
708 {-# SCC "Parser" #-} do
710 buf <- stringToStringBuffer str
712 let loc = mkSrcLoc FSLIT("<interactive>") 1 0
714 case unP parser (mkPState buf loc dflags) of {
716 PFailed span err -> do { printError span err;
721 --ToDo: can't free the string buffer until we've finished this
722 -- compilation sweep and all the identifiers have gone away.
723 dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing);
728 %************************************************************************
730 \subsection{Getting information about an identifer}
732 %************************************************************************
736 hscGetInfo -- like hscStmt, but deals with a single identifier
738 -> String -- The identifier
739 -> IO [GetInfoResult]
741 hscGetInfo hsc_env str
742 = do maybe_rdr_name <- hscParseIdentifier (hsc_dflags hsc_env) str
743 case maybe_rdr_name of {
744 Nothing -> return [];
745 Just (L _ rdr_name) -> do
747 maybe_tc_result <- tcRnGetInfo hsc_env (hsc_IC hsc_env) rdr_name
749 case maybe_tc_result of
751 Just things -> return things
756 %************************************************************************
758 Desugar, simplify, convert to bytecode, and link an expression
760 %************************************************************************
764 compileExpr :: HscEnv
765 -> Module -> GlobalRdrEnv -> TypeEnv
769 compileExpr hsc_env this_mod rdr_env type_env tc_expr
770 = do { let { dflags = hsc_dflags hsc_env ;
771 lint_on = dopt Opt_DoCoreLinting dflags }
774 ; ds_expr <- deSugarExpr hsc_env this_mod rdr_env type_env tc_expr
777 ; flat_expr <- flattenExpr hsc_env ds_expr
780 ; simpl_expr <- simplifyExpr dflags flat_expr
782 -- Tidy it (temporary, until coreSat does cloning)
783 ; let tidy_expr = tidyExpr emptyTidyEnv simpl_expr
785 -- Prepare for codegen
786 ; prepd_expr <- corePrepExpr dflags tidy_expr
789 -- ToDo: improve SrcLoc
791 case lintUnfolding noSrcLoc [] prepd_expr of
792 Just err -> pprPanic "compileExpr" err
798 ; bcos <- coreExprToBCOs dflags prepd_expr
801 ; hval <- linkExpr hsc_env bcos
809 %************************************************************************
811 Statistics on reading interfaces
813 %************************************************************************
816 dumpIfaceStats :: HscEnv -> IO ()
817 dumpIfaceStats hsc_env
818 = do { eps <- readIORef (hsc_EPS hsc_env)
819 ; dumpIfSet (dump_if_trace || dump_rn_stats)
820 "Interface statistics"
823 dflags = hsc_dflags hsc_env
824 dump_rn_stats = dopt Opt_D_dump_rn_stats dflags
825 dump_if_trace = dopt Opt_D_dump_if_trace dflags
828 %************************************************************************
830 Progress Messages: Module i of n
832 %************************************************************************
835 showModuleIndex Nothing = ""
836 showModuleIndex (Just (i,n)) = "[" ++ padded ++ " of " ++ n_str ++ "] "
840 padded = replicate (length n_str - length i_str) ' ' ++ i_str