#include "HsVersions.h"
-import CmdLineOpts ( DynFlags, DynFlag(..), dopt, opt_NoImplicitPrelude )
+import CmdLineOpts ( DynFlag(..), opt_NoImplicitPrelude )
import HsSyn ( HsModule(..), HsDecl(..), IE(..), ieName, ImportDecl(..),
+ ForeignDecl(..), ForKind(..), isDynamicExtName,
collectTopBinders
)
import RdrHsSyn ( RdrNameIE, RdrNameImportDecl,
RdrNameHsModule, RdrNameHsDecl
)
-import RnIfaces ( getInterfaceExports, getDeclBinders,
- recordLocalSlurps, checkModUsage,
- outOfDate, findAndReadIface )
+import RnIfaces ( getInterfaceExports, recordLocalSlurps )
+import RnHiFiles ( getTyClDeclBinders )
import RnEnv
import RnMonad
setLocalNameSort, nameOccName, nameEnvElts )
import HscTypes ( Provenance(..), ImportReason(..), GlobalRdrEnv,
GenAvailInfo(..), AvailInfo, Avails, AvailEnv )
-import RdrName ( RdrName, rdrNameOcc, setRdrNameOcc, mkRdrQual, mkRdrUnqual,
- isQual, isUnqual )
+import RdrName ( RdrName, rdrNameOcc, setRdrNameOcc, mkRdrQual, mkRdrUnqual, isUnqual )
import OccName ( setOccNameSpace, dataName )
import NameSet ( elemNameSet, emptyNameSet )
+import SrcLoc ( SrcLoc )
import Outputable
import Maybes ( maybeToBool, catMaybes, mapMaybe )
import UniqFM ( emptyUFM, listToUFM )
-> RnMG (Maybe (GlobalRdrEnv, -- Maps all in-scope things
GlobalRdrEnv, -- Maps just *local* things
Avails, -- The exported stuff
- AvailEnv, -- Maps a name to its parent AvailInfo
+ AvailEnv -- Maps a name to its parent AvailInfo
-- Just for in-scope things only
- Maybe ParsedIface -- The old interface file, if any
))
-- Nothing => no need to recompile
getGlobalNames (HsModule this_mod _ exports imports decls _ mod_loc)
= -- These two fix-loops are to get the right
-- provenance information into a Name
- fixRn ( \ ~(Just (rec_gbl_env, _, rec_export_avails, _, _)) ->
+ fixRn ( \ ~(Just (rec_gbl_env, _, rec_export_avails, _)) ->
let
rec_unqual_fn :: Name -> Bool -- Is this chap in scope unqualified?
-- Found errors already, so exit now
returnRn Nothing
else
- checkEarlyExit this_mod `thenRn` \ (up_to_date, old_iface) ->
- if up_to_date then
- -- Interface files are sufficiently unchanged
- putDocRn (text "Compilation IS NOT required") `thenRn_`
- returnRn Nothing
- else
-- PROCESS EXPORT LISTS
exportsFromAvail this_mod exports all_avails gbl_env `thenRn` \ export_avails ->
-- ALL DONE
- returnRn (Just (gbl_env, local_gbl_env, export_avails, global_avail_env, old_iface))
+ returnRn (Just (gbl_env, local_gbl_env, export_avails, global_avail_env))
)
where
all_imports = prel_imports ++ imports
\end{code}
\begin{code}
-checkEarlyExit mod_name
- = traceRn (text "Considering whether compilation is required...") `thenRn_`
-
- -- Read the old interface file, if any, for the module being compiled
- findAndReadIface doc_str mod_name False {- Not hi-boot -} `thenRn` \ maybe_iface ->
-
- -- CHECK WHETHER WE HAVE IT ALREADY
- case maybe_iface of
- Left err -> -- Old interface file not found, so we'd better bail out
- traceRn (vcat [ptext SLIT("No old interface file for") <+> ppr mod_name,
- err]) `thenRn_`
- returnRn (outOfDate, Nothing)
-
- Right iface
- | panic "checkEarlyExit: ???: not opt_SourceUnchanged"
- -> -- Source code changed
- traceRn (nest 4 (text "source file changed or recompilation check turned off")) `thenRn_`
- returnRn (False, Just iface)
-
- | otherwise
- -> -- Source code unchanged and no errors yet... carry on
- checkModUsage (pi_usages iface) `thenRn` \ up_to_date ->
- returnRn (up_to_date, Just iface)
- where
- -- Only look in current directory, with suffix .hi
- doc_str = sep [ptext SLIT("need usage info from"), ppr mod_name]
-\end{code}
-
-\begin{code}
importsFromImportDecl :: (Name -> Bool) -- OK to omit qualifier
-> RdrNameImportDecl
-> RnMG (GlobalRdrEnv,
\begin{code}
importsFromLocalDecls mod_name rec_exp_fn decls
- = mapRn (getLocalDeclBinders mod rec_exp_fn) decls `thenRn` \ avails_s ->
+ = mapRn (getLocalDeclBinders (newLocalName mod rec_exp_fn)) decls `thenRn` \ avails_s ->
let
avails = concat avails_s
where
mod = mkModuleInThisPackage mod_name
-getLocalDeclBinders :: Module
- -> (Name -> Bool) -- Is-exported predicate
+---------------------------
+getLocalDeclBinders :: (RdrName -> SrcLoc -> RnMG Name)
-> RdrNameHsDecl -> RnMG Avails
-getLocalDeclBinders mod rec_exp_fn (ValD binds)
+getLocalDeclBinders new_name (ValD binds)
= mapRn do_one (bagToList (collectTopBinders binds))
where
- do_one (rdr_name, loc) = newLocalName mod rec_exp_fn rdr_name loc `thenRn` \ name ->
+ do_one (rdr_name, loc) = new_name rdr_name loc `thenRn` \ name ->
returnRn (Avail name)
-getLocalDeclBinders mod rec_exp_fn decl
- = getDeclBinders (newLocalName mod rec_exp_fn) decl `thenRn` \ maybe_avail ->
- case maybe_avail of
- Nothing -> returnRn [] -- Instance decls and suchlike
- Just avail -> returnRn [avail]
+getLocalDeclBinders new_name (TyClD tycl_decl)
+ = getTyClDeclBinders new_name tycl_decl `thenRn` \ avail ->
+ returnRn [avail]
+
+getLocalDeclBinders new_name (ForD (ForeignDecl nm kind _ ext_nm _ loc))
+ | binds_haskell_name kind
+ = new_name nm loc `thenRn` \ name ->
+ returnRn [Avail name]
+
+ | otherwise -- a foreign export
+ = lookupOrigName nm `thenRn_`
+ returnRn []
+ where
+ binds_haskell_name (FoImport _) = True
+ binds_haskell_name FoLabel = True
+ binds_haskell_name FoExport = isDynamicExtName ext_nm
+
+getLocalDeclBinders new_name (FixD _) = returnRn []
+getLocalDeclBinders new_name (DeprecD _) = returnRn []
+getLocalDeclBinders new_name (DefD _) = returnRn []
+getLocalDeclBinders new_name (InstD _) = returnRn []
+getLocalDeclBinders new_name (RuleD _) = returnRn []
+
+---------------------------
newLocalName mod rec_exp_fn rdr_name loc
= check_unqual rdr_name loc `thenRn_`
newTopBinder mod rdr_name loc `thenRn` \ name ->