Commit 28e8d878 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Simplify handling of the interactive package; fixes Trac #8831

This patch is really a fix to the big commint
   73c08ab1
   Re-work the naming story for the GHCi prompt (Trac #8649)
which introduced the 'interactive' package
See Note [The interactive package] in HscTypes

The original commit set both
  (a) The tcg_mod field of TcGblEnv to 'interactive:Ghci4' (say)
  (b) The thisPackage field of DynFlags to 'interactive'

But the second step interacts badly with linking.  :loaded modules are
in the package set by 'thisPackage' (usually 'main'); if you change
that, then we try to link package 'main', but can't find it, and
that is what happened in #8831.

The fix was simple: do (a) but not (b).

I changed Note [The interactive package] in HscTypes to describe this.
parent ffed708c
......@@ -1357,11 +1357,7 @@ hscStmtWithLocation hsc_env0 stmt source linenumber =
Just parsed_stmt -> do
-- Rename and typecheck it
hsc_env <- getHscEnv
let interactive_hsc_env = setInteractivePackage hsc_env
-- Bindings created here belong to the interactive package
-- See Note [The interactive package] in HscTypes
-- (NB: maybe not necessary, since Stmts bind only Ids)
(ids, tc_expr, fix_env) <- ioMsgMaybe $ tcRnStmt interactive_hsc_env parsed_stmt
(ids, tc_expr, fix_env) <- ioMsgMaybe $ tcRnStmt hsc_env parsed_stmt
-- Desugar it
ds_expr <- ioMsgMaybe $ deSugarExpr hsc_env tc_expr
......@@ -1397,10 +1393,7 @@ hscDeclsWithLocation hsc_env0 str source linenumber =
{- Rename and typecheck it -}
hsc_env <- getHscEnv
let interactive_hsc_env = setInteractivePackage hsc_env
-- Bindings created here belong to the interactive package
-- See Note [The interactive package] in HscTypes
tc_gblenv <- ioMsgMaybe $ tcRnDeclsi interactive_hsc_env decls
tc_gblenv <- ioMsgMaybe $ tcRnDeclsi hsc_env decls
{- Grab the new instances -}
-- We grab the whole environment because of the overlapping that may have
......
......@@ -1140,10 +1140,13 @@ The details are a bit tricky though:
package to which :load'ed modules are added to.
* So how do we arrange that declarations at the command prompt get
to be in the 'interactive' package? By setting 'thisPackage' just
before the typecheck/rename step for command-line processing;
see the calls to HscTypes.setInteractivePackage in
HscMain.hscDeclsWithLocation and hscStmtWithLocation.
to be in the 'interactive' package? Simply by setting the tcg_mod
field of the TcGblEnv to "interactive:Ghci1". This is done by the
call to initTc in initTcInteractive, initTcForLookup, which in
turn get the module from it 'icInteractiveModule' field of the
interactive context.
The 'thisPackage' field stays as 'main' (or whatever -package-name says.
* The main trickiness is that the type environment (tcg_type_env and
fixity envt (tcg_fix_env) now contains entities from all the
......
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