Commit ae3ba7ec authored by David Himmelstrup's avatar David Himmelstrup
Browse files

Rather large refactoring of RnNames.

This restructoring makes the renamed export and import lists
available in IDE mode.
parent d9979e94
...@@ -730,7 +730,7 @@ data CheckedModule = ...@@ -730,7 +730,7 @@ data CheckedModule =
-- fields within CheckedModule. -- fields within CheckedModule.
type ParsedSource = Located (HsModule RdrName) type ParsedSource = Located (HsModule RdrName)
type RenamedSource = HsGroup Name type RenamedSource = (HsGroup Name, [LImportDecl Name], Maybe [LIE Name])
type TypecheckedSource = LHsBinds Id type TypecheckedSource = LHsBinds Id
-- NOTE: -- NOTE:
......
...@@ -40,7 +40,7 @@ import VarEnv ( emptyTidyEnv ) ...@@ -40,7 +40,7 @@ import VarEnv ( emptyTidyEnv )
import Var ( Id ) import Var ( Id )
import Module ( emptyModuleEnv, ModLocation(..) ) import Module ( emptyModuleEnv, ModLocation(..) )
import RdrName ( GlobalRdrEnv, RdrName ) import RdrName ( GlobalRdrEnv, RdrName )
import HsSyn ( HsModule, LHsBinds, HsGroup ) import HsSyn ( HsModule, LHsBinds, HsGroup, LIE, LImportDecl )
import SrcLoc ( Located(..) ) import SrcLoc ( Located(..) )
import StringBuffer ( hGetStringBuffer, stringToStringBuffer ) import StringBuffer ( hGetStringBuffer, stringToStringBuffer )
import Parser import Parser
...@@ -133,9 +133,12 @@ data HscResult ...@@ -133,9 +133,12 @@ data HscResult
-- In IDE mode: we just do the static/dynamic checks -- In IDE mode: we just do the static/dynamic checks
| HscChecked | HscChecked
(Located (HsModule RdrName)) -- parsed -- parsed
(Maybe (HsGroup Name)) -- renamed (Located (HsModule RdrName))
(Maybe (LHsBinds Id, GlobalRdrEnv, ModDetails)) -- typechecked -- renamed
(Maybe (HsGroup Name,[LImportDecl Name],Maybe [LIE Name]))
-- typechecked
(Maybe (LHsBinds Id, GlobalRdrEnv, ModDetails))
-- Concluded that it wasn't necessary -- Concluded that it wasn't necessary
| HscNoRecomp ModDetails -- new details (HomeSymbolTable additions) | HscNoRecomp ModDetails -- new details (HomeSymbolTable additions)
...@@ -339,8 +342,12 @@ hscFileCheck hsc_env mod_summary = do { ...@@ -339,8 +342,12 @@ hscFileCheck hsc_env mod_summary = do {
md_rules = [panic "no rules"] } md_rules = [panic "no rules"] }
-- Rules are CoreRules, not the -- Rules are CoreRules, not the
-- RuleDecls we get out of the typechecker -- RuleDecls we get out of the typechecker
rnInfo = do decl <- tcg_rn_decls tc_result
imports <- tcg_rn_imports tc_result
let exports = tcg_rn_exports tc_result
return (decl,imports,exports)
return (HscChecked rdr_module return (HscChecked rdr_module
(tcg_rn_decls tc_result) rnInfo
(Just (tcg_binds tc_result, (Just (tcg_binds tc_result,
tcg_rdr_env tc_result, tcg_rdr_env tc_result,
md))) md)))
......
This diff is collapsed.
...@@ -53,6 +53,7 @@ import TcSimplify ( tcSimplifyTop ) ...@@ -53,6 +53,7 @@ import TcSimplify ( tcSimplifyTop )
import TcTyClsDecls ( tcTyAndClassDecls ) import TcTyClsDecls ( tcTyAndClassDecls )
import LoadIface ( loadOrphanModules ) import LoadIface ( loadOrphanModules )
import RnNames ( importsFromLocalDecls, rnImports, rnExports, import RnNames ( importsFromLocalDecls, rnImports, rnExports,
mkRdrEnvAndImports, mkExportNameSet,
reportUnusedNames, reportDeprecations ) reportUnusedNames, reportDeprecations )
import RnEnv ( lookupSrcOcc_maybe ) import RnEnv ( lookupSrcOcc_maybe )
import RnSource ( rnSrcDecls, rnTyClDecls, checkModDeprec ) import RnSource ( rnSrcDecls, rnTyClDecls, checkModDeprec )
...@@ -149,7 +150,7 @@ tcRnModule :: HscEnv ...@@ -149,7 +150,7 @@ tcRnModule :: HscEnv
-> Located (HsModule RdrName) -> Located (HsModule RdrName)
-> IO (Messages, Maybe TcGblEnv) -> IO (Messages, Maybe TcGblEnv)
tcRnModule hsc_env hsc_src save_rn_decls tcRnModule hsc_env hsc_src save_rn_syntax
(L loc (HsModule maybe_mod export_ies (L loc (HsModule maybe_mod export_ies
import_decls local_decls mod_deprec)) import_decls local_decls mod_deprec))
= do { showPass (hsc_dflags hsc_env) "Renamer/typechecker" ; = do { showPass (hsc_dflags hsc_env) "Renamer/typechecker" ;
...@@ -161,8 +162,9 @@ tcRnModule hsc_env hsc_src save_rn_decls ...@@ -161,8 +162,9 @@ tcRnModule hsc_env hsc_src save_rn_decls
initTc hsc_env hsc_src this_mod $ initTc hsc_env hsc_src this_mod $
setSrcSpan loc $ setSrcSpan loc $
do { do {
-- Deal with imports; sets tcg_rdr_env, tcg_imports -- Deal with imports;
(rdr_env, imports) <- rnImports import_decls ; rn_imports <- rnImports import_decls ;
(rdr_env, imports) <- mkRdrEnvAndImports rn_imports ;
let { dep_mods :: ModuleEnv (Module, IsBootInterface) let { dep_mods :: ModuleEnv (Module, IsBootInterface)
; dep_mods = imp_dep_mods imports ; dep_mods = imp_dep_mods imports
...@@ -189,7 +191,11 @@ tcRnModule hsc_env hsc_src save_rn_decls ...@@ -189,7 +191,11 @@ tcRnModule hsc_env hsc_src save_rn_decls
gbl { tcg_rdr_env = rdr_env, gbl { tcg_rdr_env = rdr_env,
tcg_inst_env = extendInstEnvList (tcg_inst_env gbl) home_insts, tcg_inst_env = extendInstEnvList (tcg_inst_env gbl) home_insts,
tcg_imports = tcg_imports gbl `plusImportAvails` imports, tcg_imports = tcg_imports gbl `plusImportAvails` imports,
tcg_rn_decls = if save_rn_decls then tcg_rn_imports = if save_rn_syntax then
Just rn_imports
else
Nothing,
tcg_rn_decls = if save_rn_syntax then
Just emptyRnGroup Just emptyRnGroup
else else
Nothing }) Nothing })
...@@ -223,7 +229,8 @@ tcRnModule hsc_env hsc_src save_rn_decls ...@@ -223,7 +229,8 @@ tcRnModule hsc_env hsc_src save_rn_decls
reportDeprecations tcg_env ; reportDeprecations tcg_env ;
-- Process the export list -- Process the export list
exports <- rnExports (isJust maybe_mod) export_ies ; rn_exports <- rnExports export_ies ;
exports <- mkExportNameSet (isJust maybe_mod) rn_exports ;
-- Check whether the entire module is deprecated -- Check whether the entire module is deprecated
-- This happens only once per module -- This happens only once per module
...@@ -231,6 +238,9 @@ tcRnModule hsc_env hsc_src save_rn_decls ...@@ -231,6 +238,9 @@ tcRnModule hsc_env hsc_src save_rn_decls
-- Add exports and deprecations to envt -- Add exports and deprecations to envt
let { final_env = tcg_env { tcg_exports = exports, let { final_env = tcg_env { tcg_exports = exports,
tcg_rn_exports = if save_rn_syntax then
rn_exports
else Nothing,
tcg_dus = tcg_dus tcg_env `plusDU` usesOnly exports, tcg_dus = tcg_dus tcg_env `plusDU` usesOnly exports,
tcg_deprecs = tcg_deprecs tcg_env `plusDeprecs` tcg_deprecs = tcg_deprecs tcg_env `plusDeprecs`
mod_deprecs } mod_deprecs }
......
...@@ -98,6 +98,8 @@ initTc hsc_env hsc_src mod do_this ...@@ -98,6 +98,8 @@ initTc hsc_env hsc_src mod do_this
tcg_imports = init_imports, tcg_imports = init_imports,
tcg_home_mods = home_mods, tcg_home_mods = home_mods,
tcg_dus = emptyDUs, tcg_dus = emptyDUs,
tcg_rn_imports = Nothing,
tcg_rn_exports = Nothing,
tcg_rn_decls = Nothing, tcg_rn_decls = Nothing,
tcg_binds = emptyLHsBinds, tcg_binds = emptyLHsBinds,
tcg_deprecs = NoDeprecs, tcg_deprecs = NoDeprecs,
......
...@@ -43,7 +43,8 @@ module TcRnTypes( ...@@ -43,7 +43,8 @@ module TcRnTypes(
#include "HsVersions.h" #include "HsVersions.h"
import HsSyn ( PendingSplice, HsOverLit, LRuleDecl, LForeignDecl, import HsSyn ( PendingSplice, HsOverLit, LRuleDecl, LForeignDecl,
ArithSeqInfo, DictBinds, LHsBinds, HsGroup ) ArithSeqInfo, DictBinds, LHsBinds, LImportDecl, HsGroup,
IE )
import HscTypes ( FixityEnv, import HscTypes ( FixityEnv,
HscEnv, TypeEnv, TyThing, HscEnv, TypeEnv, TyThing,
GenAvailInfo(..), AvailInfo, HscSource(..), GenAvailInfo(..), AvailInfo, HscSource(..),
...@@ -62,7 +63,7 @@ import OccName ( OccEnv ) ...@@ -62,7 +63,7 @@ import OccName ( OccEnv )
import Var ( Id, TyVar ) import Var ( Id, TyVar )
import VarEnv ( TidyEnv ) import VarEnv ( TidyEnv )
import Module import Module
import SrcLoc ( SrcSpan, SrcLoc, srcSpanStart ) import SrcLoc ( SrcSpan, SrcLoc, Located, srcSpanStart )
import VarSet ( IdSet ) import VarSet ( IdSet )
import ErrUtils ( Messages, Message ) import ErrUtils ( Messages, Message )
import UniqSupply ( UniqSupply ) import UniqSupply ( UniqSupply )
...@@ -217,6 +218,8 @@ data TcGblEnv ...@@ -217,6 +218,8 @@ data TcGblEnv
-- collected initially in un-zonked form and are -- collected initially in un-zonked form and are
-- finally zonked in tcRnSrcDecls -- finally zonked in tcRnSrcDecls
tcg_rn_imports :: Maybe [LImportDecl Name],
tcg_rn_exports :: Maybe [Located (IE Name)],
tcg_rn_decls :: Maybe (HsGroup Name), -- renamed decls, maybe tcg_rn_decls :: Maybe (HsGroup Name), -- renamed decls, maybe
-- Nothing <=> Don't retain renamed decls -- Nothing <=> Don't retain renamed decls
...@@ -726,6 +729,7 @@ cmpInst (LitInst _ lit1 ty1 _) (LitInst _ lit2 ty2 _) = (lit1 `compare` lit2) ` ...@@ -726,6 +729,7 @@ cmpInst (LitInst _ lit1 ty1 _) (LitInst _ lit2 ty2 _) = (lit1 `compare` lit2) `
%************************************************************************ %************************************************************************
\begin{code} \begin{code}
-- FIXME: Rename this. It clashes with (Located (IE ...))
type LIE = Bag Inst type LIE = Bag Inst
isEmptyLIE = isEmptyBag isEmptyLIE = isEmptyBag
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment