import Type ( Type )
import PrelNames ( iNTERACTIVE )
import StringBuffer ( stringToStringBuffer )
+import Name ( Name )
+import CoreLint ( lintUnfolding )
#endif
import HsSyn
import StringBuffer ( hGetStringBuffer, freeStringBuffer )
import Parser
import Lex ( ParseResult(..), ExtFlags(..), mkPState )
-import SrcLoc ( mkSrcLoc )
+import SrcLoc ( mkSrcLoc, noSrcLoc )
import TcRnDriver ( checkOldIface, tcRnModule, tcRnExtCore, tcRnIface )
+import RnEnv ( extendOrigNameCache )
import Rules ( emptyRuleBase )
-import PrelInfo ( wiredInThingEnv, wiredInThings, knownKeyNames )
+import PrelInfo ( wiredInThingEnv, knownKeyNames )
import PrelRules ( builtinRules )
import MkIface ( mkIface )
import InstEnv ( emptyInstEnv )
import CodeGen ( codeGen )
import CodeOutput ( codeOutput )
-import Module ( ModuleName, moduleName )
+import Module ( emptyModuleEnv )
import CmdLineOpts
import DriverPhases ( isExtCore_file )
import ErrUtils ( dumpIfSet_dyn, showPass, printError )
import MkExternalCore ( emitExternalCore )
import ParserCore
import ParserCoreUtils
-import FiniteMap ( FiniteMap, plusFM, emptyFM, addToFM )
-import OccName ( OccName )
-import Name ( Name, nameModule, nameOccName, getName )
+import FiniteMap ( emptyFM )
+import Name ( nameModule, getName )
import NameEnv ( emptyNameEnv, mkNameEnv )
import NameSet ( emptyNameSet )
import Module ( Module, ModLocation(..), showModMsg )
-- PARSE
-------------------
; maybe_parsed <- myParseModule (hsc_dflags hsc_env)
- (expectJust "hscRecomp:hspp" (ml_hspp_file location))
+ (expectJust "hscFrontEnd:hspp" (ml_hspp_file location))
; case maybe_parsed of {
Nothing -> return (Left (HscFail pcs_ch));
; case maybe_tc_result of {
Nothing -> return (Left (HscFail pcs_ch));
Just tc_result -> do {
-
+
-------------------
-- DESUGAR
-------------------
------------------ Code output -----------------------
(stub_h_exists, stub_c_exists)
- <- codeOutput dflags prepd_result
- stg_binds abstractC
+ <- codeOutput dflags prepd_result abstractC
return (stub_h_exists, stub_c_exists, Nothing)
-- Then desugar, code gen, and link it
; hval <- compileExpr hsc_env pcs1 iNTERACTIVE
- (icPrintUnqual new_ic) tc_expr
+ (ic_rn_gbl_env new_ic)
+ (ic_type_env new_ic)
+ tc_expr
; return (pcs1, Just (new_ic, bound_names, hval))
}}}}}
#ifdef GHCI
compileExpr :: HscEnv
-> PersistentCompilerState
- -> Module -> PrintUnqualified
+ -> Module -> GlobalRdrEnv -> TypeEnv
-> TypecheckedHsExpr
-> IO HValue
-compileExpr hsc_env pcs this_mod print_unqual tc_expr
- = do { let dflags = hsc_dflags hsc_env
-
+compileExpr hsc_env pcs this_mod rdr_env type_env tc_expr
+ = do { let { dflags = hsc_dflags hsc_env ;
+ lint_on = dopt Opt_DoCoreLinting dflags }
+
-- Desugar it
- ; ds_expr <- deSugarExpr hsc_env pcs this_mod print_unqual tc_expr
+ ; ds_expr <- deSugarExpr hsc_env pcs this_mod rdr_env type_env tc_expr
-- Flatten it
; flat_expr <- flattenExpr hsc_env pcs ds_expr
-- Prepare for codegen
; prepd_expr <- corePrepExpr dflags tidy_expr
+ -- Lint if necessary
+ -- ToDo: improve SrcLoc
+ ; if lint_on then
+ case lintUnfolding noSrcLoc [] prepd_expr of
+ Just err -> pprPanic "compileExpr" err
+ Nothing -> return ()
+ else
+ return ()
+
-- Convert to BCOs
; bcos <- coreExprToBCOs dflags prepd_expr
eps_insts = (emptyBag, 0),
eps_inst_gates = emptyNameSet,
eps_rules = foldr add_rule (emptyBag, 0) builtinRules,
- eps_imp_mods = emptyFM,
eps_PIT = emptyPackageIfaceTable,
eps_PTE = wiredInThingEnv,
where
gated_decl = (gate_fn, (mod, IfaceRuleOut rdr_name rule))
mod = nameModule name
- rdr_name = nameRdrName name
- gate_fn vis_fn = vis_fn name -- Load the rule whenever name is visible
-
-initOrigNames :: FiniteMap (ModuleName,OccName) Name
-initOrigNames
- = grab knownKeyNames `plusFM` grab (map getName wiredInThings)
- where
- grab names = foldl add emptyFM names
- add env name
- = addToFM env (moduleName (nameModule name), nameOccName name) name
+ rdr_name = nameRdrName name -- Seems a bit of a hack to go back
+ -- to the RdrName
+ gate_fn vis_fn = vis_fn name -- Load the rule whenever name is visible
+
+initOrigNames :: OrigNameCache
+initOrigNames = foldl extendOrigNameCache emptyModuleEnv knownKeyNames
\end{code}