[project @ 2003-09-10 16:44:03 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / HscMain.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-2000
3 %
4
5 \section[GHC_Main]{Main driver for Glasgow Haskell compiler}
6
7 \begin{code}
8 module HscMain ( 
9         HscResult(..), hscMain, initPersistentCompilerState
10 #ifdef GHCI
11         , hscStmt, hscTcExpr, hscThing, 
12         , compileExpr
13 #endif
14         ) where
15
16 #include "HsVersions.h"
17
18 #ifdef GHCI
19 import TcHsSyn          ( TypecheckedHsExpr )
20 import CodeOutput       ( outputForeignStubs )
21 import ByteCodeGen      ( byteCodeGen, coreExprToBCOs )
22 import Linker           ( HValue, linkExpr )
23 import TidyPgm          ( tidyCoreExpr )
24 import CorePrep         ( corePrepExpr )
25 import Flattening       ( flattenExpr )
26 import TcRnDriver       ( tcRnStmt, tcRnExpr, tcRnThing ) 
27 import RdrHsSyn         ( RdrNameStmt )
28 import Type             ( Type )
29 import PrelNames        ( iNTERACTIVE )
30 import StringBuffer     ( stringToStringBuffer )
31 import SrcLoc           ( noSrcLoc )
32 import Name             ( Name )
33 import CoreLint         ( lintUnfolding )
34 #endif
35
36 import HsSyn
37
38 import RdrName          ( nameRdrName )
39 import StringBuffer     ( hGetStringBuffer )
40 import Parser
41 import Lexer            ( P(..), ParseResult(..), mkPState, showPFailed )
42 import SrcLoc           ( mkSrcLoc )
43 import TcRnDriver       ( checkOldIface, tcRnModule, tcRnExtCore, tcRnIface )
44 import RnEnv            ( extendOrigNameCache )
45 import PrelInfo         ( wiredInThingEnv, knownKeyNames )
46 import PrelRules        ( builtinRules )
47 import MkIface          ( mkIface )
48 import Desugar
49 import Flattening       ( flatten )
50 import SimplCore
51 import TidyPgm          ( tidyCorePgm )
52 import CorePrep         ( corePrepPgm )
53 import CoreToStg        ( coreToStg )
54 import SimplStg         ( stg2stg )
55 import CodeGen          ( codeGen )
56 import CodeOutput       ( codeOutput )
57
58 import Module           ( emptyModuleEnv )
59 import CmdLineOpts
60 import DriverPhases     ( isExtCore_file )
61 import ErrUtils         ( dumpIfSet_dyn, showPass )
62 import UniqSupply       ( mkSplitUniqSupply )
63
64 import Bag              ( consBag, emptyBag )
65 import Outputable
66 import HscStats         ( ppSourceStats )
67 import HscTypes
68 import MkExternalCore   ( emitExternalCore )
69 import ParserCore
70 import ParserCoreUtils
71 import FiniteMap        ( emptyFM )
72 import Name             ( nameModule )
73 import Module           ( Module, ModLocation(..), showModMsg )
74 import FastString
75 import Maybes           ( expectJust )
76
77 import Monad            ( when )
78 import Maybe            ( isJust, fromJust )
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                  Bool                   -- stub_h exists
102                  Bool                   -- stub_c exists
103                  (Maybe CompiledByteCode)
104
105         -- no errors or warnings; the individual passes
106         -- (parse/rename/typecheck) print messages themselves
107
108 hscMain
109   :: HscEnv
110   -> PersistentCompilerState    -- IN: persistent compiler state
111   -> Module
112   -> ModLocation                -- location info
113   -> Bool                       -- True <=> source unchanged
114   -> Bool                       -- True <=> have an object file (for msgs only)
115   -> Maybe ModIface             -- old interface, if available
116   -> IO HscResult
117
118 hscMain hsc_env pcs mod location 
119         source_unchanged have_object maybe_old_iface
120  = do {
121       (pcs_ch, maybe_chk_result) <- _scc_ "checkOldIface" 
122                                     checkOldIface hsc_env pcs mod 
123                                                   (ml_hi_file location)
124                                                   source_unchanged maybe_old_iface;
125       case maybe_chk_result of {
126         Nothing -> return (HscFail pcs_ch) ;
127         Just (recomp_reqd, maybe_checked_iface) -> do {
128
129       let no_old_iface = not (isJust maybe_checked_iface)
130           what_next | recomp_reqd || no_old_iface = hscRecomp 
131                     | otherwise                   = hscNoRecomp
132
133       ; what_next hsc_env pcs_ch have_object 
134                   mod location maybe_checked_iface
135       }}}
136
137
138 -- hscNoRecomp definitely expects to have the old interface available
139 hscNoRecomp hsc_env pcs_ch have_object 
140             mod location (Just old_iface)
141  | hsc_mode hsc_env == OneShot
142  = do {
143       when (verbosity (hsc_dflags hsc_env) > 0) $
144           hPutStrLn stderr "compilation IS NOT required";
145       let { bomb = panic "hscNoRecomp:OneShot" };
146       return (HscNoRecomp pcs_ch bomb bomb)
147       }
148  | otherwise
149  = do {
150       when (verbosity (hsc_dflags hsc_env) >= 1) $
151                 hPutStrLn stderr ("Skipping  " ++ 
152                         showModMsg have_object mod location);
153
154       -- Typecheck 
155       (pcs_tc, maybe_tc_result) <- _scc_ "tcRnIface"
156                                    tcRnIface hsc_env pcs_ch old_iface ;
157
158       case maybe_tc_result of {
159          Nothing -> return (HscFail pcs_tc);
160          Just new_details ->
161
162       return (HscNoRecomp pcs_tc new_details old_iface)
163       }}
164
165 hscRecomp hsc_env pcs_ch have_object 
166           mod location maybe_checked_iface
167  = do   {
168           -- what target are we shooting for?
169         ; let one_shot  = hsc_mode hsc_env == OneShot
170         ; let dflags    = hsc_dflags hsc_env
171         ; let toInterp  = dopt_HscLang dflags == HscInterpreted
172         ; let toCore    = isJust (ml_hs_file location) &&
173                           isExtCore_file (fromJust (ml_hs_file location))
174
175         ; when (not one_shot && verbosity dflags >= 1) $
176                 hPutStrLn stderr ("Compiling " ++ 
177                         showModMsg (not toInterp) mod location);
178                         
179         ; front_res <- if toCore then 
180                           hscCoreFrontEnd hsc_env pcs_ch location
181                        else 
182                           hscFrontEnd hsc_env pcs_ch location
183
184         ; case front_res of
185             Left flure -> return flure;
186             Right (pcs_tc, ds_result) -> do {
187
188
189         -- OMITTED: 
190         -- ; seqList imported_modules (return ())
191
192             -------------------
193             -- FLATTENING
194             -------------------
195         ; flat_result <- _scc_ "Flattening"
196                          flatten hsc_env pcs_tc ds_result
197
198
199         ; let   -- Rule-base accumulated from imported packages
200              pkg_rule_base = eps_rule_base (pcs_EPS pcs_tc)
201
202                 -- In one-shot mode, ZAP the external package state at
203                 -- this point, because we aren't going to need it from
204                 -- now on.  We keep the name cache, however, because
205                 -- tidyCore needs it.
206              pcs_middle 
207                  | one_shot  = pcs_tc{ pcs_EPS = error "pcs_EPS missing" }
208                  | otherwise = pcs_tc
209
210         ; pkg_rule_base `seq` pcs_middle `seq` return ()
211
212         -- alive at this point:  
213         --      pcs_middle
214         --      flat_result
215         --      pkg_rule_base
216
217             -------------------
218             -- SIMPLIFY
219             -------------------
220         ; simpl_result <- _scc_     "Core2Core"
221                           core2core hsc_env pkg_rule_base flat_result
222
223             -------------------
224             -- TIDY
225             -------------------
226         ; (pcs_simpl, tidy_result) 
227              <- _scc_ "CoreTidy"
228                 tidyCorePgm dflags pcs_middle simpl_result
229
230         -- ZAP the persistent compiler state altogether now if we're
231         -- in one-shot mode, to save space.
232         ; pcs_final <- if one_shot then return (error "pcs_final missing")
233                                    else return pcs_simpl
234
235         ; emitExternalCore dflags tidy_result
236
237         -- Alive at this point:  
238         --      tidy_result, pcs_final
239         --      hsc_env
240
241             -------------------
242             -- BUILD THE NEW ModIface and ModDetails
243             --  and emit external core if necessary
244             -- This has to happen *after* code gen so that the back-end
245             -- info has been set.  Not yet clear if it matters waiting
246             -- until after code output
247         ; new_iface <- _scc_ "MkFinalIface" 
248                         mkIface hsc_env location 
249                                 maybe_checked_iface tidy_result
250
251
252             -- Space leak reduction: throw away the new interface if
253             -- we're in one-shot mode; we won't be needing it any
254             -- more.
255         ; final_iface <-
256              if one_shot then return (error "no final iface")
257                          else return new_iface
258
259             -- Build the final ModDetails (except in one-shot mode, where
260             -- we won't need this information after compilation).
261         ; final_details <- 
262              if one_shot then return (error "no final details")
263                          else return $! ModDetails { 
264                                            md_types = mg_types tidy_result,
265                                            md_insts = mg_insts tidy_result,
266                                            md_rules = mg_rules tidy_result }
267
268             -------------------
269             -- CONVERT TO STG and COMPLETE CODE GENERATION
270         ; (stub_h_exists, stub_c_exists, maybe_bcos)
271                 <- hscBackEnd dflags tidy_result
272
273           -- and the answer is ...
274         ; return (HscRecomp pcs_final
275                             final_details
276                             final_iface
277                             stub_h_exists stub_c_exists
278                             maybe_bcos)
279          }}
280
281 hscCoreFrontEnd hsc_env pcs_ch location = do {
282             -------------------
283             -- PARSE
284             -------------------
285         ; inp <- readFile (expectJust "hscCoreFrontEnd:hspp" (ml_hspp_file location))
286         ; case parseCore inp 1 of
287             FailP s        -> hPutStrLn stderr s >> return (Left (HscFail pcs_ch));
288             OkP rdr_module -> do {
289     
290             -------------------
291             -- RENAME and TYPECHECK
292             -------------------
293         ; (pcs_tc, maybe_tc_result) <- _scc_ "TypeCheck" 
294                                        tcRnExtCore hsc_env pcs_ch rdr_module
295         ; case maybe_tc_result of {
296              Nothing       -> return (Left  (HscFail pcs_tc));
297              Just mod_guts -> return (Right (pcs_tc, mod_guts))
298                                         -- No desugaring to do!
299         }}}
300          
301
302 hscFrontEnd hsc_env pcs_ch location = do {
303             -------------------
304             -- PARSE
305             -------------------
306         ; maybe_parsed <- myParseModule (hsc_dflags hsc_env) 
307                              (expectJust "hscFrontEnd:hspp" (ml_hspp_file location))
308
309         ; case maybe_parsed of {
310              Nothing -> return (Left (HscFail pcs_ch));
311              Just rdr_module -> do {
312     
313             -------------------
314             -- RENAME and TYPECHECK
315             -------------------
316         ; (pcs_tc, maybe_tc_result) <- _scc_ "Typecheck-Rename" 
317                                         tcRnModule hsc_env pcs_ch rdr_module
318         ; case maybe_tc_result of {
319              Nothing -> return (Left (HscFail pcs_ch));
320              Just tc_result -> do {
321
322             -------------------
323             -- DESUGAR
324             -------------------
325         ; ds_result <- _scc_ "DeSugar" 
326                        deSugar hsc_env pcs_tc tc_result
327         ; return (Right (pcs_tc, ds_result))
328         }}}}}
329
330
331 hscBackEnd dflags 
332     ModGuts{  -- This is the last use of the ModGuts in a compilation.
333               -- From now on, we just use the bits we need.
334         mg_module   = this_mod,
335         mg_binds    = core_binds,
336         mg_types    = type_env,
337         mg_dir_imps = dir_imps,
338         mg_foreign  = foreign_stubs,
339         mg_deps     = dependencies     }  = do {
340
341             -------------------
342             -- PREPARE FOR CODE GENERATION
343             -- Do saturation and convert to A-normal form
344   prepd_binds <- _scc_ "CorePrep"
345                  corePrepPgm dflags core_binds type_env;
346
347   case dopt_HscLang dflags of
348       HscNothing -> return (False, False, Nothing)
349
350       HscInterpreted ->
351 #ifdef GHCI
352         do  -----------------  Generate byte code ------------------
353             comp_bc <- byteCodeGen dflags prepd_binds type_env
354         
355             ------------------ Create f-x-dynamic C-side stuff ---
356             (istub_h_exists, istub_c_exists) 
357                <- outputForeignStubs dflags foreign_stubs
358             
359             return ( istub_h_exists, istub_c_exists, Just comp_bc )
360 #else
361         panic "GHC not compiled with interpreter"
362 #endif
363
364       other ->
365         do
366             -----------------  Convert to STG ------------------
367             (stg_binds, cost_centre_info) <- _scc_ "CoreToStg"
368                          myCoreToStg dflags this_mod prepd_binds        
369
370             ------------------  Code generation ------------------
371             abstractC <- _scc_ "CodeGen"
372                          codeGen dflags this_mod type_env foreign_stubs
373                                  dir_imps cost_centre_info stg_binds
374
375             ------------------  Code output -----------------------
376             (stub_h_exists, stub_c_exists)
377                      <- codeOutput dflags this_mod foreign_stubs 
378                                 dependencies abstractC
379
380             return (stub_h_exists, stub_c_exists, Nothing)
381    }
382
383
384 myParseModule dflags src_filename
385  = do --------------------------  Parser  ----------------
386       showPass dflags "Parser"
387       _scc_  "Parser" do
388       buf <- hGetStringBuffer src_filename
389
390       let loc  = mkSrcLoc (mkFastString src_filename) 1 0
391
392       case unP parseModule (mkPState buf loc dflags) of {
393
394         PFailed l1 l2 err -> do { hPutStrLn stderr (showPFailed l1 l2 err);
395                                   return Nothing };
396
397         POk _ rdr_module -> do {
398
399       dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_module) ;
400       
401       dumpIfSet_dyn dflags Opt_D_source_stats "Source Statistics"
402                            (ppSourceStats False rdr_module) ;
403       
404       return (Just rdr_module)
405         -- ToDo: free the string buffer later.
406       }}
407
408
409 myCoreToStg dflags this_mod prepd_binds
410  = do 
411       stg_binds <- _scc_ "Core2Stg" 
412              coreToStg dflags prepd_binds
413
414       (stg_binds2, cost_centre_info) <- _scc_ "Core2Stg" 
415              stg2stg dflags this_mod stg_binds
416
417       return (stg_binds2, cost_centre_info)
418 \end{code}
419
420
421 %************************************************************************
422 %*                                                                      *
423 \subsection{Compiling a do-statement}
424 %*                                                                      *
425 %************************************************************************
426
427 When the UnlinkedBCOExpr is linked you get an HValue of type
428         IO [HValue]
429 When you run it you get a list of HValues that should be 
430 the same length as the list of names; add them to the ClosureEnv.
431
432 A naked expression returns a singleton Name [it].
433
434         What you type                   The IO [HValue] that hscStmt returns
435         -------------                   ------------------------------------
436         let pat = expr          ==>     let pat = expr in return [coerce HVal x, coerce HVal y, ...]
437                                         bindings: [x,y,...]
438
439         pat <- expr             ==>     expr >>= \ pat -> return [coerce HVal x, coerce HVal y, ...]
440                                         bindings: [x,y,...]
441
442         expr (of IO type)       ==>     expr >>= \ v -> return [v]
443           [NB: result not printed]      bindings: [it]
444           
445
446         expr (of non-IO type, 
447           result showable)      ==>     let v = expr in print v >> return [v]
448                                         bindings: [it]
449
450         expr (of non-IO type, 
451           result not showable)  ==>     error
452
453 \begin{code}
454 #ifdef GHCI
455 hscStmt         -- Compile a stmt all the way to an HValue, but don't run it
456   :: HscEnv
457   -> PersistentCompilerState    -- IN: persistent compiler state
458   -> InteractiveContext         -- Context for compiling
459   -> String                     -- The statement
460   -> IO ( PersistentCompilerState, 
461           Maybe (InteractiveContext, [Name], HValue) )
462
463 hscStmt hsc_env pcs icontext stmt
464   = do  { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) stmt
465         ; case maybe_stmt of {
466              Nothing -> return (pcs, Nothing) ;
467              Just parsed_stmt -> do {
468
469                 -- Rename and typecheck it
470           (pcs1, maybe_tc_result)
471                  <- tcRnStmt hsc_env pcs icontext parsed_stmt
472
473         ; case maybe_tc_result of {
474                 Nothing -> return (pcs1, Nothing) ;
475                 Just (new_ic, bound_names, tc_expr) -> do {
476
477                 -- Then desugar, code gen, and link it
478         ; hval <- compileExpr hsc_env pcs1 iNTERACTIVE 
479                               (ic_rn_gbl_env new_ic) 
480                               (ic_type_env new_ic)
481                               tc_expr
482
483         ; return (pcs1, Just (new_ic, bound_names, hval))
484         }}}}}
485
486 hscTcExpr       -- Typecheck an expression (but don't run it)
487   :: HscEnv
488   -> PersistentCompilerState    -- IN: persistent compiler state
489   -> InteractiveContext         -- Context for compiling
490   -> String                     -- The expression
491   -> IO (PersistentCompilerState, Maybe Type)
492
493 hscTcExpr hsc_env pcs icontext expr
494   = do  { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) expr
495         ; case maybe_stmt of {
496              Just (ExprStmt expr _ _) 
497                         -> tcRnExpr hsc_env pcs icontext expr ;
498              Just other -> do { hPutStrLn stderr ("not an expression: `" ++ expr ++ "'") ;
499                                 return (pcs, Nothing) } ;
500              Nothing    -> return (pcs, Nothing) } }
501 \end{code}
502
503 \begin{code}
504 hscParseStmt :: DynFlags -> String -> IO (Maybe RdrNameStmt)
505 hscParseStmt dflags str
506  = do showPass dflags "Parser"
507       _scc_ "Parser"  do
508
509       buf <- stringToStringBuffer str
510
511       let loc  = mkSrcLoc FSLIT("<interactive>") 1 0
512
513       case unP parseStmt (mkPState buf loc dflags) of {
514
515         PFailed l1 l2 err -> do { hPutStrLn stderr (showPFailed l1 l2 err);     
516                                   return Nothing };
517
518         -- no stmt: the line consisted of just space or comments
519         POk _ Nothing -> return Nothing;
520
521         POk _ (Just rdr_stmt) -> do {
522
523       --ToDo: can't free the string buffer until we've finished this
524       -- compilation sweep and all the identifiers have gone away.
525       dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_stmt);
526       return (Just rdr_stmt)
527       }}
528 #endif
529 \end{code}
530
531 %************************************************************************
532 %*                                                                      *
533 \subsection{Getting information about an identifer}
534 %*                                                                      *
535 %************************************************************************
536
537 \begin{code}
538 #ifdef GHCI
539 hscThing -- like hscStmt, but deals with a single identifier
540   :: HscEnv
541   -> PersistentCompilerState    -- IN: persistent compiler state
542   -> InteractiveContext         -- Context for compiling
543   -> String                     -- The identifier
544   -> IO ( PersistentCompilerState,
545           [TyThing] )
546
547 hscThing hsc_env pcs0 ic str
548    = do let dflags         = hsc_dflags hsc_env
549
550         maybe_rdr_name <- myParseIdentifier dflags str
551         case maybe_rdr_name of {
552           Nothing -> return (pcs0, []);
553           Just rdr_name -> do
554
555         (pcs1, maybe_tc_result) <- 
556            tcRnThing hsc_env pcs0 ic rdr_name
557
558         case maybe_tc_result of {
559              Nothing     -> return (pcs1, []) ;
560              Just things -> return (pcs1, things)
561         }}
562
563 myParseIdentifier dflags str
564   = do buf <- stringToStringBuffer str
565  
566        let loc  = mkSrcLoc FSLIT("<interactive>") 1 0
567        case unP parseIdentifier (mkPState buf loc dflags) of
568
569           PFailed l1 l2 err -> do { hPutStrLn stderr (showPFailed l1 l2 err);
570                                     return Nothing }
571
572           POk _ rdr_name -> return (Just rdr_name)
573 #endif
574 \end{code}
575
576 %************************************************************************
577 %*                                                                      *
578         Desugar, simplify, convert to bytecode, and link an expression
579 %*                                                                      *
580 %************************************************************************
581
582 \begin{code}
583 #ifdef GHCI
584 compileExpr :: HscEnv 
585             -> PersistentCompilerState
586             -> Module -> GlobalRdrEnv -> TypeEnv
587             -> TypecheckedHsExpr
588             -> IO HValue
589
590 compileExpr hsc_env pcs this_mod rdr_env type_env tc_expr
591   = do  { let { dflags  = hsc_dflags hsc_env ;
592                 lint_on = dopt Opt_DoCoreLinting dflags }
593               
594                 -- Desugar it
595         ; ds_expr <- deSugarExpr hsc_env pcs this_mod rdr_env type_env tc_expr
596         
597                 -- Flatten it
598         ; flat_expr <- flattenExpr hsc_env pcs ds_expr
599
600                 -- Simplify it
601         ; simpl_expr <- simplifyExpr dflags flat_expr
602
603                 -- Tidy it (temporary, until coreSat does cloning)
604         ; tidy_expr <- tidyCoreExpr simpl_expr
605
606                 -- Prepare for codegen
607         ; prepd_expr <- corePrepExpr dflags tidy_expr
608
609                 -- Lint if necessary
610                 -- ToDo: improve SrcLoc
611         ; if lint_on then 
612                 case lintUnfolding noSrcLoc [] prepd_expr of
613                    Just err -> pprPanic "compileExpr" err
614                    Nothing  -> return ()
615           else
616                 return ()
617
618                 -- Convert to BCOs
619         ; bcos <- coreExprToBCOs dflags prepd_expr
620
621                 -- link it
622         ; hval <- linkExpr hsc_env pcs bcos
623
624         ; return hval
625      }
626 #endif
627 \end{code}
628
629
630 %************************************************************************
631 %*                                                                      *
632 \subsection{Initial persistent state}
633 %*                                                                      *
634 %************************************************************************
635
636 \begin{code}
637 initPersistentCompilerState :: IO PersistentCompilerState
638 initPersistentCompilerState 
639   = do nc <- initNameCache
640        return (
641         PCS { pcs_EPS = initExternalPackageState,
642               pcs_nc  = nc })
643
644 initNameCache :: IO NameCache
645   = do us <- mkSplitUniqSupply 'r'
646        return (NameCache { nsUniqs = us,
647                            nsNames = initOrigNames,
648                            nsIPs   = emptyFM })
649
650 initExternalPackageState :: ExternalPackageState
651 initExternalPackageState
652   = emptyExternalPackageState { 
653       eps_rules  = foldr add_rule (emptyBag, 0) builtinRules,
654       eps_PTE    = wiredInThingEnv,
655     }
656   where
657     add_rule (name,rule) (rules, n_slurped)
658          = (gated_decl `consBag` rules, n_slurped)
659         where
660            gated_decl = (gate_fn, (mod, IfaceRuleOut rdr_name rule))
661            mod        = nameModule name
662            rdr_name   = nameRdrName name        -- Seems a bit of a hack to go back
663                                                 -- to the RdrName
664            gate_fn vis_fn = vis_fn name         -- Load the rule whenever name is visible
665
666 initOrigNames :: OrigNameCache
667 initOrigNames = foldl extendOrigNameCache emptyModuleEnv knownKeyNames 
668 \end{code}