- tryLoadInterface doc (moduleName this_module) ImportByUser
- `thenRn` \ (iface, maybe_err) ->
- case maybe_err of {
- Just msg -> ioToRnM (printErrs alwaysQualify
- (ptext SLIT("failed to load interface for")
- <+> quotes (ppr this_module)
- <> char ':' <+> msg)) `thenRn_`
- returnRn Nothing;
- Nothing ->
-
- let rdr_env = mi_globals iface
- print_unqual = unQualInScope rdr_env
- in
-
- initRnMS rdr_env emptyLocalFixityEnv CmdLineMode (rnExpr expr)
- `thenRn` \ (e,fvs) ->
-
- checkErrsRn `thenRn` \ no_errs_so_far ->
- if not no_errs_so_far then
- -- Found errors already, so exit now
- doDump e [] `thenRn_`
- returnRn Nothing
- else
-
- addImplicitFVs rdr_env Nothing fvs `thenRn` \ (slurp_fvs, syntax_map) ->
- slurpImpDecls slurp_fvs `thenRn` \ decls ->
-
- doDump e decls `thenRn_`
- returnRn (Just (print_unqual, (syntax_map, e, decls)))
- }
+
+ -- Load the interface for the context module, so
+ -- that we can get its top-level lexical environment
+ -- Bale out if we fail to do this
+ loadInterface doc (moduleName scope_module) ImportByUser `thenRn` \ iface ->
+ let rdr_env = mi_globals iface
+ print_unqual = unQualInScope rdr_env
+ in
+ checkErrsRn `thenRn` \ no_errs_so_far ->
+ if not no_errs_so_far then
+ returnRn (print_unqual, Nothing)
+ else
+
+ -- Rename it
+ initRnMS rdr_env local_env emptyLocalFixityEnv CmdLineMode (
+ rnStmt stmt $ \ stmt' ->
+ returnRn (([], stmt'), emptyFVs)
+ ) `thenRn` \ ((binders, stmt), fvs) ->
+
+ -- Bale out if we fail
+ checkErrsRn `thenRn` \ no_errs_so_far ->
+ if not no_errs_so_far then
+ doDump [] stmt [] `thenRn_` returnRn (print_unqual, Nothing)
+ else
+
+ -- Add implicit free vars, and close decls
+ getImplicitStmtFVs `thenRn` \ implicit_fvs ->
+ let
+ filtered_fvs = fvs `delListFromNameSet` rdrEnvElts local_env
+ source_fvs = implicit_fvs `plusFV` filtered_fvs
+ in
+ slurpImpDecls source_fvs `thenRn` \ decls ->
+
+ doDump binders stmt decls `thenRn_`
+ returnRn (print_unqual, Just (binders, (vanillaSyntaxMap, stmt, decls)))
+