[project @ 2001-03-13 17:08:36 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / HscMain.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-2000
3 %
4 \section[GHC_Main]{Main driver for Glasgow Haskell compiler}
5
6 \begin{code}
7 module HscMain ( HscResult(..), hscMain, 
8 #ifdef GHCI
9                  hscStmt,
10 #endif
11                  initPersistentCompilerState ) where
12
13 #include "HsVersions.h"
14
15 #ifdef GHCI
16 import ByteCodeGen      ( byteCodeGen )
17 import CoreTidy         ( tidyCoreExpr )
18 import CorePrep         ( corePrepExpr )
19 import Rename           ( renameStmt )
20 import RdrHsSyn         ( RdrNameStmt )
21 import Type             ( Type )
22 import Id               ( Id, idName, setGlobalIdDetails )
23 import IdInfo           ( GlobalIdDetails(VanillaGlobal) )
24 import HscTypes         ( InteractiveContext(..), TyThing(..) )
25 import PrelNames        ( iNTERACTIVE )
26 import StringBuffer     ( stringToStringBuffer )
27 #endif
28
29 import HsSyn
30
31 import Id               ( idName )
32 import IdInfo           ( CafInfo(..), CgInfoEnv, CgInfo(..) )
33 import StringBuffer     ( hGetStringBuffer, freeStringBuffer )
34 import Parser
35 import Lex              ( PState(..), ParseResult(..) )
36 import SrcLoc           ( mkSrcLoc )
37 import Rename           ( checkOldIface, renameModule, closeIfaceDecls )
38 import Rules            ( emptyRuleBase )
39 import PrelInfo         ( wiredInThingEnv, wiredInThings )
40 import PrelNames        ( vanillaSyntaxMap, knownKeyNames )
41 import MkIface          ( completeIface, writeIface, pprIface )
42 import TcModule
43 import InstEnv          ( emptyInstEnv )
44 import Desugar
45 import SimplCore
46 import CoreUtils        ( coreBindsSize )
47 import CoreTidy         ( tidyCorePgm )
48 import CorePrep         ( corePrepPgm )
49 import StgSyn
50 import CoreToStg        ( coreToStg )
51 import SimplStg         ( stg2stg )
52 import CodeGen          ( codeGen )
53 import CodeOutput       ( codeOutput )
54
55 import Module           ( ModuleName, moduleName, mkHomeModule, 
56                           moduleUserString )
57 import CmdLineOpts
58 import ErrUtils         ( dumpIfSet_dyn, showPass, printError )
59 import Util             ( unJust )
60 import UniqSupply       ( mkSplitUniqSupply )
61
62 import Bag              ( emptyBag )
63 import Outputable
64 import Interpreter
65 import CmStaticInfo     ( GhciMode(..) )
66 import HscStats         ( ppSourceStats )
67 import HscTypes
68 import FiniteMap        ( FiniteMap, plusFM, emptyFM, addToFM )
69 import OccName          ( OccName )
70 import Name             ( Name, nameModule, nameOccName, getName, isGlobalName )
71 import NameEnv          ( emptyNameEnv, mkNameEnv )
72 import Module           ( Module, lookupModuleEnvByName )
73 import Maybes           ( orElse )
74
75 import IOExts           ( newIORef, readIORef, writeIORef, unsafePerformIO )
76
77 import Monad            ( when )
78 import Maybe            ( isJust )
79 import IO
80 \end{code}
81
82
83 %************************************************************************
84 %*                                                                      *
85 \subsection{The main compiler pipeline}
86 %*                                                                      *
87 %************************************************************************
88
89 \begin{code}
90 data HscResult
91    -- compilation failed
92    = HscFail     PersistentCompilerState -- updated PCS
93    -- concluded that it wasn't necessary
94    | HscNoRecomp PersistentCompilerState -- updated PCS
95                  ModDetails              -- new details (HomeSymbolTable additions)
96                  ModIface                -- new iface (if any compilation was done)
97    -- did recompilation
98    | HscRecomp   PersistentCompilerState -- updated PCS
99                  ModDetails              -- new details (HomeSymbolTable additions)
100                  ModIface                -- new iface (if any compilation was done)
101                  (Maybe String)          -- generated stub_h filename (in TMPDIR)
102                  (Maybe String)          -- generated stub_c filename (in TMPDIR)
103                  (Maybe ([UnlinkedBCO],ItblEnv)) -- interpreted code, if any
104              
105
106         -- no errors or warnings; the individual passes
107         -- (parse/rename/typecheck) print messages themselves
108
109 hscMain
110   :: GhciMode
111   -> DynFlags
112   -> Module
113   -> ModuleLocation             -- location info
114   -> Bool                       -- source unchanged?
115   -> Maybe ModIface             -- old interface, if available
116   -> HomeSymbolTable            -- for home module ModDetails
117   -> HomeIfaceTable
118   -> PersistentCompilerState    -- IN: persistent compiler state
119   -> IO HscResult
120
121 hscMain ghci_mode dflags mod location source_unchanged maybe_old_iface hst hit pcs
122  = do {
123       showPass dflags ("Checking old interface for hs = " 
124                         ++ show (ml_hs_file location)
125                         ++ ", hspp = " ++ show (ml_hspp_file location));
126
127       (pcs_ch, errs_found, (recomp_reqd, maybe_checked_iface))
128          <- checkOldIface ghci_mode dflags hit hst pcs 
129                 (unJust "hscMain" (ml_hi_file location))
130                 source_unchanged maybe_old_iface;
131
132       if errs_found then
133          return (HscFail pcs_ch)
134       else do {
135
136       let no_old_iface = not (isJust maybe_checked_iface)
137           what_next | recomp_reqd || no_old_iface = hscRecomp 
138                     | otherwise                   = hscNoRecomp
139       ;
140       what_next ghci_mode dflags mod location maybe_checked_iface
141                 hst hit pcs_ch
142       }}
143
144
145 -- we definitely expect to have the old interface available
146 hscNoRecomp ghci_mode dflags mod location (Just old_iface) hst hit pcs_ch
147  | ghci_mode == OneShot
148  = do {
149       hPutStrLn stderr "compilation IS NOT required";
150       let { bomb = panic "hscNoRecomp:OneShot" };
151       return (HscNoRecomp pcs_ch bomb bomb)
152       }
153  | otherwise
154  = do {
155       when (verbosity dflags >= 1) $
156                 hPutStrLn stderr ("Skipping  " ++ compMsg mod location);
157
158       -- CLOSURE
159       (pcs_cl, closure_errs, cl_hs_decls) 
160          <- closeIfaceDecls dflags hit hst pcs_ch old_iface ;
161       if closure_errs then 
162          return (HscFail pcs_cl) 
163       else do {
164
165       -- TYPECHECK
166       maybe_tc_result 
167         <- typecheckIface dflags pcs_cl hst old_iface (vanillaSyntaxMap, cl_hs_decls);
168
169       case maybe_tc_result of {
170          Nothing -> return (HscFail pcs_cl);
171          Just (pcs_tc, new_details) ->
172
173       return (HscNoRecomp pcs_tc new_details old_iface)
174       }}}
175
176 compMsg mod location =
177     mod_str ++ take (12 - length mod_str) (repeat ' ')
178     ++ " (" ++ unJust "hscRecomp" (ml_hs_file location) ++ ")"
179  where mod_str = moduleUserString mod
180
181
182 hscRecomp ghci_mode dflags mod location maybe_checked_iface hst hit pcs_ch
183  = do   {
184         ; when (verbosity dflags >= 1) $
185                 hPutStrLn stderr ("Compiling " ++ compMsg mod location);
186
187           -- what target are we shooting for?
188         ; let toInterp = dopt_HscLang dflags == HscInterpreted
189
190             -------------------
191             -- PARSE
192             -------------------
193         ; maybe_parsed <- myParseModule dflags 
194                              (unJust "hscRecomp:hspp" (ml_hspp_file location))
195         ; case maybe_parsed of {
196              Nothing -> return (HscFail pcs_ch);
197              Just rdr_module -> do {
198         ; let this_mod = mkHomeModule (hsModuleName rdr_module)
199     
200             -------------------
201             -- RENAME
202             -------------------
203         ; (pcs_rn, print_unqualified, maybe_rn_result) 
204              <- _scc_ "Rename" 
205                  renameModule dflags hit hst pcs_ch this_mod rdr_module
206         ; case maybe_rn_result of {
207              Nothing -> return (HscFail pcs_ch{-was: pcs_rn-});
208              Just (is_exported, new_iface, rn_hs_decls) -> do {
209     
210             -- In interactive mode, we don't want to discard any top-level entities at
211             -- all (eg. do not inline them away during simplification), and retain them
212             -- all in the TypeEnv so they are available from the command line.
213             --
214             -- isGlobalName separates the user-defined top-level names from those
215             -- introduced by the type checker.
216         ; let dont_discard | ghci_mode == Interactive = isGlobalName
217                            | otherwise = is_exported
218
219             -------------------
220             -- TYPECHECK
221             -------------------
222         ; maybe_tc_result 
223             <- _scc_ "TypeCheck" typecheckModule dflags pcs_rn hst new_iface 
224                                              print_unqualified rn_hs_decls 
225         ; case maybe_tc_result of {
226              Nothing -> return (HscFail pcs_ch{-was: pcs_rn-});
227              Just (pcs_tc, tc_result) -> do {
228     
229             -------------------
230             -- DESUGAR
231             -------------------
232         ; (ds_details, foreign_stuff) 
233              <- _scc_ "DeSugar" 
234                 deSugar dflags pcs_tc hst this_mod print_unqualified tc_result
235
236             -------------------
237             -- SIMPLIFY
238             -------------------
239         ; simpl_details
240              <- _scc_     "Core2Core"
241                 core2core dflags pcs_tc hst dont_discard ds_details
242
243             -------------------
244             -- TIDY
245             -------------------
246         ; cg_info_ref <- newIORef Nothing ;
247         ; let cg_info :: CgInfoEnv
248               cg_info = unsafePerformIO $ do {
249                            maybe_cg_env <- readIORef cg_info_ref ;
250                            case maybe_cg_env of
251                              Just env -> return env
252                              Nothing  -> do { printError "Urk! Looked at CgInfo too early!";
253                                               return emptyNameEnv } }
254                 -- cg_info_ref will be filled in just after restOfCodeGeneration
255                 -- Meanwhile, tidyCorePgm is careful not to look at cg_info!
256
257         ; (pcs_simpl, tidy_details) 
258              <- tidyCorePgm dflags this_mod pcs_tc cg_info simpl_details
259       
260             -------------------
261             -- PREPARE FOR CODE GENERATION
262             -------------------
263               -- Do saturation and convert to A-normal form
264         ; prepd_details <- corePrepPgm dflags tidy_details
265
266             -------------------
267             -- CONVERT TO STG and COMPLETE CODE GENERATION
268             -------------------
269         ; let
270             ModDetails{md_binds=binds, md_types=env_tc} = prepd_details
271
272             local_tycons     = typeEnvTyCons  env_tc
273             local_classes    = typeEnvClasses env_tc
274
275             imported_module_names = map ideclName (hsModuleImports rdr_module)
276             imported_modules = map mod_name_to_Module imported_module_names
277
278             (h_code,c_code,fe_binders) = foreign_stuff
279         
280             pit = pcs_PIT pcs_simpl
281
282             mod_name_to_Module :: ModuleName -> Module
283             mod_name_to_Module nm
284                = let str_mi = lookupModuleEnvByName hit nm `orElse`
285                               lookupModuleEnvByName pit nm `orElse`
286                               pprPanic "mod_name_to_Module: no hst or pst mapping for" 
287                                 (ppr nm)
288                  in  mi_module str_mi
289
290         ; (maybe_stub_h_filename, maybe_stub_c_filename,
291            maybe_bcos, final_iface )
292            <- if toInterp
293                 then do 
294                     -----------------  Generate byte code ------------------
295                     (bcos,itbl_env) <- byteCodeGen dflags binds 
296                                         local_tycons local_classes
297
298                     -- Fill in the code-gen info
299                     writeIORef cg_info_ref (Just emptyNameEnv)
300
301                     ------------------ BUILD THE NEW ModIface ------------
302                     final_iface <- _scc_ "MkFinalIface" 
303                           mkFinalIface ghci_mode dflags location 
304                                    maybe_checked_iface new_iface tidy_details
305
306                     return ( Nothing, Nothing, 
307                              Just (bcos,itbl_env), final_iface )
308
309                 else do
310                     -----------------  Convert to STG ------------------
311                     (stg_binds, cost_centre_info, stg_back_end_info) 
312                               <- _scc_ "CoreToStg"
313                                   myCoreToStg dflags this_mod binds
314                     
315                     -- Fill in the code-gen info for the earlier tidyCorePgm
316                     writeIORef cg_info_ref (Just stg_back_end_info)
317
318                     ------------------ BUILD THE NEW ModIface ------------
319                     final_iface <- _scc_ "MkFinalIface" 
320                           mkFinalIface ghci_mode dflags location 
321                                    maybe_checked_iface new_iface tidy_details
322
323                     ------------------  Code generation ------------------
324                     abstractC <- _scc_ "CodeGen"
325                                   codeGen dflags this_mod imported_modules
326                                          cost_centre_info fe_binders
327                                          local_tycons stg_binds
328                     
329                     ------------------  Code output -----------------------
330                     (maybe_stub_h_name, maybe_stub_c_name)
331                        <- codeOutput dflags this_mod local_tycons
332                              binds stg_binds
333                              c_code h_code abstractC
334                         
335                     return ( maybe_stub_h_name, maybe_stub_c_name, 
336                              Nothing, final_iface )
337
338         ; let final_details = tidy_details {md_binds = []} 
339
340
341           -- and the answer is ...
342         ; return (HscRecomp pcs_simpl
343                             final_details
344                             final_iface
345                             maybe_stub_h_filename maybe_stub_c_filename
346                             maybe_bcos)
347           }}}}}}}
348
349
350
351 mkFinalIface ghci_mode dflags location 
352         maybe_old_iface new_iface new_details
353  = case completeIface maybe_old_iface new_iface new_details of
354
355       (new_iface, Nothing) -- no change in the interfacfe
356          -> do when (dopt Opt_D_dump_hi_diffs dflags)
357                     (printDump (text "INTERFACE UNCHANGED"))
358                dumpIfSet_dyn dflags Opt_D_dump_hi
359                              "UNCHANGED FINAL INTERFACE" (pprIface new_iface)
360                return new_iface
361
362       (new_iface, Just sdoc_diffs)
363          -> do dumpIfSet_dyn dflags Opt_D_dump_hi_diffs "INTERFACE HAS CHANGED" 
364                                     sdoc_diffs
365                dumpIfSet_dyn dflags Opt_D_dump_hi "NEW FINAL INTERFACE" 
366                                     (pprIface new_iface)
367
368                -- Write the interface file, if not in interactive mode
369                when (ghci_mode /= Interactive) 
370                     (writeIface (unJust "hscRecomp:hi" (ml_hi_file location))
371                                 new_iface)
372                return new_iface
373
374
375 myParseModule dflags src_filename
376  = do --------------------------  Parser  ----------------
377       showPass dflags "Parser"
378       _scc_  "Parser" do
379
380       buf <- hGetStringBuffer True{-expand tabs-} src_filename
381
382       let glaexts | dopt Opt_GlasgowExts dflags = 1#
383                   | otherwise                   = 0#
384
385       case parseModule buf PState{ bol = 0#, atbol = 1#,
386                                    context = [], glasgow_exts = glaexts,
387                                    loc = mkSrcLoc (_PK_ src_filename) 1 } of {
388
389         PFailed err -> do { hPutStrLn stderr (showSDoc err);
390                             freeStringBuffer buf;
391                             return Nothing };
392
393         POk _ rdr_module@(HsModule mod_name _ _ _ _ _ _) -> do {
394
395       dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_module) ;
396       
397       dumpIfSet_dyn dflags Opt_D_source_stats "Source Statistics"
398                            (ppSourceStats False rdr_module) ;
399       
400       return (Just rdr_module)
401         -- ToDo: free the string buffer later.
402       }}
403
404
405 myCoreToStg dflags this_mod tidy_binds
406  = do 
407       () <- coreBindsSize tidy_binds `seq` return ()
408       -- TEMP: the above call zaps some space usage allocated by the
409       -- simplifier, which for reasons I don't understand, persists
410       -- thoroughout code generation
411
412       stg_binds <- _scc_ "Core2Stg" coreToStg dflags tidy_binds
413
414       (stg_binds2, cost_centre_info)
415            <- _scc_ "Core2Stg" stg2stg dflags this_mod stg_binds
416
417       let env_rhs :: CgInfoEnv
418           env_rhs = mkNameEnv [ (idName bndr, CgInfo (stgRhsArity rhs) caf_info)
419                               | (bind,_) <- stg_binds2, 
420                                 let caf_info 
421                                      | stgBindHasCafRefs bind = MayHaveCafRefs
422                                      | otherwise = NoCafRefs,
423                                 (bndr,rhs) <- stgBindPairs bind ]
424
425       return (stg_binds2, cost_centre_info, env_rhs)
426    where
427       stgBindPairs (StgNonRec _ b r) = [(b,r)]
428       stgBindPairs (StgRec    _ prs) = prs
429 \end{code}
430
431
432 %************************************************************************
433 %*                                                                      *
434 \subsection{Compiling a do-statement}
435 %*                                                                      *
436 %************************************************************************
437
438 \begin{code}
439 #ifdef GHCI
440 hscStmt
441   :: DynFlags
442   -> HomeSymbolTable    
443   -> HomeIfaceTable
444   -> PersistentCompilerState    -- IN: persistent compiler state
445   -> InteractiveContext         -- Context for compiling
446   -> String                     -- The statement
447   -> Bool                       -- just treat it as an expression
448   -> IO ( PersistentCompilerState, 
449           Maybe ( [Id], 
450                   Type, 
451                   UnlinkedBCOExpr) )
452 \end{code}
453
454 When the UnlinkedBCOExpr is linked you get an HValue of type
455         IO [HValue]
456 When you run it you get a list of HValues that should be 
457 the same length as the list of names; add them to the ClosureEnv.
458
459 A naked expression returns a singleton Name [it].
460
461         What you type                   The IO [HValue] that hscStmt returns
462         -------------                   ------------------------------------
463         let pat = expr          ==>     let pat = expr in return [coerce HVal x, coerce HVal y, ...]
464                                         bindings: [x,y,...]
465
466         pat <- expr             ==>     expr >>= \ pat -> return [coerce HVal x, coerce HVal y, ...]
467                                         bindings: [x,y,...]
468
469         expr (of IO type)       ==>     expr >>= \ v -> return [v]
470           [NB: result not printed]      bindings: [it]
471           
472
473         expr (of non-IO type, 
474           result showable)      ==>     let v = expr in print v >> return [v]
475                                         bindings: [it]
476
477         expr (of non-IO type, 
478           result not showable)  ==>     error
479
480 \begin{code}
481 hscStmt dflags hst hit pcs0 icontext stmt just_expr
482    = let 
483         InteractiveContext { 
484              ic_rn_env   = rn_env, 
485              ic_type_env = type_env,
486              ic_module   = scope_mod } = icontext
487      in
488      do { maybe_stmt <- hscParseStmt dflags stmt
489         ; case maybe_stmt of
490              Nothing -> return (pcs0, Nothing)
491              Just parsed_stmt -> do {
492
493            let { notExprStmt (ExprStmt _ _) = False;
494                  notExprStmt _              = True 
495                };
496
497            if (just_expr && notExprStmt parsed_stmt)
498                 then do hPutStrLn stderr ("not an expression: `" ++ stmt ++ "'")
499                         return (pcs0, Nothing)
500                 else do {
501
502                 -- Rename it
503           (pcs1, print_unqual, maybe_renamed_stmt)
504                  <- renameStmt dflags hit hst pcs0 scope_mod 
505                                 iNTERACTIVE rn_env parsed_stmt
506
507         ; case maybe_renamed_stmt of
508                 Nothing -> return (pcs0, Nothing)
509                 Just (bound_names, rn_stmt) -> do {
510
511                 -- Typecheck it
512           maybe_tc_return <- 
513             if just_expr 
514                 then case rn_stmt of { (syn, ExprStmt e _, decls) -> 
515                      typecheckExpr dflags pcs1 hst type_env
516                            print_unqual iNTERACTIVE (syn,e,decls) }
517                 else typecheckStmt dflags pcs1 hst type_env
518                            print_unqual iNTERACTIVE bound_names rn_stmt
519
520         ; case maybe_tc_return of
521                 Nothing -> return (pcs0, Nothing)
522                 Just (pcs2, tc_expr, bound_ids, ty) ->  do {
523
524                 -- Desugar it
525           ds_expr <- deSugarExpr dflags pcs2 hst iNTERACTIVE print_unqual tc_expr
526         
527                 -- Simplify it
528         ; simpl_expr <- simplifyExpr dflags pcs2 hst ds_expr
529
530                 -- Tidy it (temporary, until coreSat does cloning)
531         ; tidy_expr <- tidyCoreExpr simpl_expr
532
533                 -- Prepare for codegen
534         ; prepd_expr <- corePrepExpr dflags tidy_expr
535
536                 -- Convert to BCOs
537         ; bcos <- coreExprToBCOs dflags prepd_expr
538
539         ; let
540                 -- Make all the bound ids "global" ids, now that
541                 -- they're notionally top-level bindings.  This is
542                 -- important: otherwise when we come to compile an expression
543                 -- using these ids later, the byte code generator will consider
544                 -- the occurrences to be free rather than global.
545              global_bound_ids = map globaliseId bound_ids;
546              globaliseId id   = setGlobalIdDetails id VanillaGlobal
547
548         ; return (pcs2, Just (global_bound_ids, ty, bcos))
549
550      }}}}}
551
552 hscParseStmt :: DynFlags -> String -> IO (Maybe RdrNameStmt)
553 hscParseStmt dflags str
554  = do --------------------------  Parser  ----------------
555       showPass dflags "Parser"
556       _scc_ "Parser" do
557
558       buf <- stringToStringBuffer str
559
560       let glaexts | dopt Opt_GlasgowExts dflags = 1#
561                   | otherwise                   = 0#
562
563       case parseStmt buf PState{ bol = 0#, atbol = 1#,
564                                  context = [], glasgow_exts = glaexts,
565                                  loc = mkSrcLoc SLIT("<no file>") 0 } of {
566
567         PFailed err -> do { hPutStrLn stderr (showSDoc err);
568 --      Not yet implemented in <4.11    freeStringBuffer buf;
569                             return Nothing };
570
571         -- no stmt: the line consisted of just space or comments
572         POk _ Nothing -> return Nothing;
573
574         POk _ (Just rdr_stmt) -> do {
575
576       --ToDo: can't free the string buffer until we've finished this
577       -- compilation sweep and all the identifiers have gone away.
578       --freeStringBuffer buf;
579       dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_stmt);
580       return (Just rdr_stmt)
581       }}
582 #endif
583 \end{code}
584
585 %************************************************************************
586 %*                                                                      *
587 \subsection{Initial persistent state}
588 %*                                                                      *
589 %************************************************************************
590
591 \begin{code}
592 initPersistentCompilerState :: IO PersistentCompilerState
593 initPersistentCompilerState 
594   = do prs <- initPersistentRenamerState
595        return (
596         PCS { pcs_PIT   = emptyIfaceTable,
597               pcs_PTE   = wiredInThingEnv,
598               pcs_insts = emptyInstEnv,
599               pcs_rules = emptyRuleBase,
600               pcs_PRS   = prs
601             }
602         )
603
604 initPersistentRenamerState :: IO PersistentRenamerState
605   = do us <- mkSplitUniqSupply 'r'
606        return (
607         PRS { prsOrig  = NameSupply { nsUniqs = us,
608                                       nsNames = initOrigNames,
609                                       nsIPs   = emptyFM },
610               prsDecls   = (emptyNameEnv, 0),
611               prsInsts   = (emptyBag, 0),
612               prsRules   = (emptyBag, 0),
613               prsImpMods = emptyFM
614             }
615         )
616
617 initOrigNames :: FiniteMap (ModuleName,OccName) Name
618 initOrigNames 
619    = grab knownKeyNames `plusFM` grab (map getName wiredInThings)
620      where
621         grab names = foldl add emptyFM names
622         add env name 
623            = addToFM env (moduleName (nameModule name), nameOccName name) name
624
625
626 initRules :: PackageRuleBase
627 initRules = emptyRuleBase
628 {- SHOULD BE (ish)
629             foldl add emptyVarEnv builtinRules
630           where
631             add env (name,rule) 
632               = extendRuleBase env name rule
633 -}
634 \end{code}